diff options
author | Robert Jaros <rjaros@finn.pl> | 2020-05-20 17:12:56 +0200 |
---|---|---|
committer | Robert Jaros <rjaros@finn.pl> | 2020-05-20 17:12:56 +0200 |
commit | ef1abc3b975e1c77fc8663c5e5e95769fc934551 (patch) | |
tree | 343236378e2f24514635fb5e892043a054c86170 /kvision-modules/kvision-bootstrap-datetime | |
parent | 35628c364d9768a5589559b99cb698ebc2b56eba (diff) | |
download | kvision-ef1abc3b975e1c77fc8663c5e5e95769fc934551.tar.gz kvision-ef1abc3b975e1c77fc8663c5e5e95769fc934551.tar.bz2 kvision-ef1abc3b975e1c77fc8663c5e5e95769fc934551.zip |
Make all stateful components implement ObservableState interface
Diffstat (limited to 'kvision-modules/kvision-bootstrap-datetime')
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)) + } + } } /** |