diff options
Diffstat (limited to 'kvision-modules/kvision-bootstrap-datetime/src/main')
2 files changed, 18 insertions, 2 deletions
diff --git a/kvision-modules/kvision-bootstrap-datetime/src/main/kotlin/pl/treksoft/kvision/form/time/DateTime.kt b/kvision-modules/kvision-bootstrap-datetime/src/main/kotlin/pl/treksoft/kvision/form/time/DateTime.kt index 68ec96a2..115781cd 100644 --- a/kvision-modules/kvision-bootstrap-datetime/src/main/kotlin/pl/treksoft/kvision/form/time/DateTime.kt +++ b/kvision-modules/kvision-bootstrap-datetime/src/main/kotlin/pl/treksoft/kvision/form/time/DateTime.kt @@ -28,6 +28,7 @@ import pl.treksoft.kvision.form.DateFormControl import pl.treksoft.kvision.form.FieldLabel import pl.treksoft.kvision.form.InvalidFeedback import pl.treksoft.kvision.panel.SimplePanel +import pl.treksoft.kvision.state.ObservableState import pl.treksoft.kvision.utils.SnOn import kotlin.js.Date @@ -44,7 +45,7 @@ import kotlin.js.Date open class DateTime( value: Date? = null, name: String? = null, format: String = "YYYY-MM-DD HH:mm", label: String? = null, rich: Boolean = false -) : SimplePanel(setOf("form-group")), DateFormControl { +) : SimplePanel(setOf("form-group")), DateFormControl, ObservableState<Date?> { /** * Date/time input value. @@ -264,6 +265,12 @@ open class DateTime( input.blur() } + override fun getState(): Date? = input.getState() + + override fun subscribe(observer: (Date?) -> Unit): () -> Unit { + return input.subscribe(observer) + } + companion object { internal var counter = 0 } diff --git a/kvision-modules/kvision-bootstrap-datetime/src/main/kotlin/pl/treksoft/kvision/form/time/DateTimeInput.kt b/kvision-modules/kvision-bootstrap-datetime/src/main/kotlin/pl/treksoft/kvision/form/time/DateTimeInput.kt index 967ca9db..d870947b 100644 --- a/kvision-modules/kvision-bootstrap-datetime/src/main/kotlin/pl/treksoft/kvision/form/time/DateTimeInput.kt +++ b/kvision-modules/kvision-bootstrap-datetime/src/main/kotlin/pl/treksoft/kvision/form/time/DateTimeInput.kt @@ -33,6 +33,7 @@ import pl.treksoft.kvision.html.icon import pl.treksoft.kvision.html.span import pl.treksoft.kvision.i18n.I18n import pl.treksoft.kvision.panel.SimplePanel +import pl.treksoft.kvision.state.ObservableState import pl.treksoft.kvision.types.toDateF import pl.treksoft.kvision.types.toStringF import pl.treksoft.kvision.utils.obj @@ -53,7 +54,7 @@ internal const val DEFAULT_STEPPING = 5 open class DateTimeInput( value: Date? = null, format: String = "YYYY-MM-DD HH:mm", classes: Set<String> = setOf() -) : SimplePanel(classes + "input-group" + "date"), FormInput { +) : SimplePanel(classes + "input-group" + "date"), FormInput, ObservableState<Date?> { private var initialized = false @@ -404,6 +405,14 @@ open class DateTimeInput( override fun blur() { input.blur() } + + override fun getState(): Date? = input.getState()?.toDateF(format) + + override fun subscribe(observer: (Date?) -> Unit): () -> Unit { + return input.subscribe { str -> + observer(str?.toDateF(format)) + } + } } /** |