aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/pl/treksoft/kvision/form/time
diff options
context:
space:
mode:
authorRobert Jaros <rjaros@finn.pl>2018-03-26 09:34:38 +0200
committerRobert Jaros <rjaros@finn.pl>2018-03-26 09:41:24 +0200
commit6287ce18301d58792e803bc7daa7068c164e704d (patch)
treecf90971cb887e8f16317f5b795bd5825b3bde29e /src/main/kotlin/pl/treksoft/kvision/form/time
parent3b1eae9ed8b7e1d57f8f05968820c5eb4bbe8fe2 (diff)
downloadkvision-6287ce18301d58792e803bc7daa7068c164e704d.tar.gz
kvision-6287ce18301d58792e803bc7daa7068c164e704d.tar.bz2
kvision-6287ce18301d58792e803bc7daa7068c164e704d.zip
Plain HTML form attributes (method, action, enctype, target, ...) support.
Form controls refactoring.
Diffstat (limited to 'src/main/kotlin/pl/treksoft/kvision/form/time')
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/form/time/DateTime.kt30
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/form/time/DateTimeInput.kt9
2 files changed, 13 insertions, 26 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/form/time/DateTime.kt b/src/main/kotlin/pl/treksoft/kvision/form/time/DateTime.kt
index ecf930e2..3d32fd8c 100644
--- a/src/main/kotlin/pl/treksoft/kvision/form/time/DateTime.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/form/time/DateTime.kt
@@ -36,12 +36,13 @@ import kotlin.js.Date
*
* @constructor
* @param value date/time input value
+ * @param name the name attribute of the generated HTML input element
* @param format date/time format (default YYYY-MM-DD HH:mm)
* @param label label text bound to the input element
* @param rich determines if [label] can contain HTML code
*/
open class DateTime(
- value: Date? = null, format: String = "YYYY-MM-DD HH:mm", label: String? = null,
+ value: Date? = null, name: String? = null, format: String = "YYYY-MM-DD HH:mm", label: String? = null,
rich: Boolean = false
) : SimplePanel(setOf("form-group")), DateFormControl {
@@ -70,19 +71,6 @@ open class DateTime(
input.placeholder = value
}
/**
- * The name attribute of the generated HTML input element.
- */
- var name
- get() = input.name
- set(value) {
- input.name = value
- }
- override var disabled
- get() = input.disabled
- set(value) {
- input.disabled = value
- }
- /**
* Determines if the date/time input is automatically focused.
*/
var autofocus
@@ -170,14 +158,12 @@ open class DateTime(
set(value) {
flabel.rich = value
}
- override var size
- get() = input.size
- set(value) {
- input.size = value
- }
private val idc = "kv_form_time_$counter"
- final override val input: DateTimeInput = DateTimeInput(value, format).apply { id = idc }
+ final override val input: DateTimeInput = DateTimeInput(value, format).apply {
+ this.id = idc
+ this.name = name
+ }
final override val flabel: FieldLabel = FieldLabel(idc, label, rich)
final override val validationInfo: HelpBlock = HelpBlock().apply { visible = false }
@@ -249,10 +235,10 @@ open class DateTime(
* It takes the same parameters as the constructor of the built component.
*/
fun Container.dateTime(
- value: Date? = null, format: String = "YYYY-MM-DD HH:mm", label: String? = null,
+ value: Date? = null, name: String? = null, format: String = "YYYY-MM-DD HH:mm", label: String? = null,
rich: Boolean = false, init: (DateTime.() -> Unit)? = null
): DateTime {
- val dateTime = DateTime(value, format, label, rich).apply { init?.invoke(this) }
+ val dateTime = DateTime(value, name, format, label, rich).apply { init?.invoke(this) }
this.add(dateTime)
return dateTime
}
diff --git a/src/main/kotlin/pl/treksoft/kvision/form/time/DateTimeInput.kt b/src/main/kotlin/pl/treksoft/kvision/form/time/DateTimeInput.kt
index d935487b..86e9c7ba 100644
--- a/src/main/kotlin/pl/treksoft/kvision/form/time/DateTimeInput.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/form/time/DateTimeInput.kt
@@ -26,6 +26,7 @@ import pl.treksoft.kvision.core.Container
import pl.treksoft.kvision.core.StringBoolPair
import pl.treksoft.kvision.core.StringPair
import pl.treksoft.kvision.core.Widget
+import pl.treksoft.kvision.form.FormInput
import pl.treksoft.kvision.form.InputSize
import pl.treksoft.kvision.utils.obj
import pl.treksoft.kvision.utils.toDateF
@@ -47,7 +48,7 @@ internal const val MAX_VIEW = 4
open class DateTimeInput(
value: Date? = null, format: String = "YYYY-MM-DD HH:mm",
classes: Set<String> = setOf()
-) : Widget(classes + "form-control") {
+) : Widget(classes + "form-control"), FormInput {
init {
this.setInternalEventListener<DateTimeInput> {
@@ -72,11 +73,11 @@ open class DateTimeInput(
/**
* The name attribute of the generated HTML input element.
*/
- var name: String? by refreshOnUpdate()
+ override var name: String? by refreshOnUpdate()
/**
* Determines if the field is disabled.
*/
- var disabled by refreshOnUpdate(false)
+ override var disabled by refreshOnUpdate(false)
/**
* Determines if the text input is automatically focused.
*/
@@ -88,7 +89,7 @@ open class DateTimeInput(
/**
* The size of the input.
*/
- var size: InputSize? by refreshOnUpdate()
+ override var size: InputSize? by refreshOnUpdate()
/**
* Day of the week start. 0 (Sunday) to 6 (Saturday).
*/