aboutsummaryrefslogtreecommitdiff
path: root/kvision-modules/kvision-bootstrap-spinner/src
diff options
context:
space:
mode:
Diffstat (limited to 'kvision-modules/kvision-bootstrap-spinner/src')
-rw-r--r--kvision-modules/kvision-bootstrap-spinner/src/main/kotlin/pl/treksoft/kvision/form/spinner/Spinner.kt9
-rw-r--r--kvision-modules/kvision-bootstrap-spinner/src/main/kotlin/pl/treksoft/kvision/form/spinner/SpinnerInput.kt17
2 files changed, 23 insertions, 3 deletions
diff --git a/kvision-modules/kvision-bootstrap-spinner/src/main/kotlin/pl/treksoft/kvision/form/spinner/Spinner.kt b/kvision-modules/kvision-bootstrap-spinner/src/main/kotlin/pl/treksoft/kvision/form/spinner/Spinner.kt
index 3901cc4f..2dbcd443 100644
--- a/kvision-modules/kvision-bootstrap-spinner/src/main/kotlin/pl/treksoft/kvision/form/spinner/Spinner.kt
+++ b/kvision-modules/kvision-bootstrap-spinner/src/main/kotlin/pl/treksoft/kvision/form/spinner/Spinner.kt
@@ -30,6 +30,7 @@ import pl.treksoft.kvision.form.InvalidFeedback
import pl.treksoft.kvision.form.NumberFormControl
import pl.treksoft.kvision.html.ButtonStyle
import pl.treksoft.kvision.panel.SimplePanel
+import pl.treksoft.kvision.state.ObservableState
import pl.treksoft.kvision.utils.SnOn
/**
@@ -52,7 +53,7 @@ open class Spinner(
decimals: Int = 0, val buttonsType: ButtonsType = ButtonsType.VERTICAL,
forceType: ForceType = ForceType.NONE, buttonStyle: ButtonStyle? = null, label: String? = null,
rich: Boolean = false
-) : SimplePanel(setOf("form-group")), NumberFormControl {
+) : SimplePanel(setOf("form-group")), NumberFormControl, ObservableState<Number?> {
/**
* Spinner value.
@@ -252,6 +253,12 @@ open class Spinner(
invalidFeedback.addCssClass("col-sm-${horizontalRatio.fields}")
}
+ override fun getState(): Number? = input.getState()
+
+ override fun subscribe(observer: (Number?) -> Unit): () -> Unit {
+ return input.subscribe(observer)
+ }
+
companion object {
internal var counter = 0
}
diff --git a/kvision-modules/kvision-bootstrap-spinner/src/main/kotlin/pl/treksoft/kvision/form/spinner/SpinnerInput.kt b/kvision-modules/kvision-bootstrap-spinner/src/main/kotlin/pl/treksoft/kvision/form/spinner/SpinnerInput.kt
index 98b7be62..9ed9d707 100644
--- a/kvision-modules/kvision-bootstrap-spinner/src/main/kotlin/pl/treksoft/kvision/form/spinner/SpinnerInput.kt
+++ b/kvision-modules/kvision-bootstrap-spinner/src/main/kotlin/pl/treksoft/kvision/form/spinner/SpinnerInput.kt
@@ -31,6 +31,7 @@ import pl.treksoft.kvision.form.FormInput
import pl.treksoft.kvision.form.InputSize
import pl.treksoft.kvision.form.ValidationStatus
import pl.treksoft.kvision.html.ButtonStyle
+import pl.treksoft.kvision.state.ObservableState
import pl.treksoft.kvision.utils.obj
import pl.treksoft.kvision.utils.set
@@ -75,12 +76,14 @@ open class SpinnerInput(
decimals: Int = 0, val buttonsType: ButtonsType = ButtonsType.VERTICAL,
forceType: ForceType = ForceType.NONE, buttonStyle: ButtonStyle? = null,
classes: Set<String> = setOf()
-) : Widget(classes + "form-control"), FormInput {
+) : Widget(classes + "form-control"), FormInput, ObservableState<Number?> {
+
+ protected val observers = mutableListOf<(Number?) -> Unit>()
/**
* Spinner value.
*/
- var value by refreshOnUpdate(value) { refreshState() }
+ var value by refreshOnUpdate(value) { refreshState(); observers.forEach { ob -> ob(it) } }
/**
* The value attribute of the generated HTML input element.
@@ -328,6 +331,16 @@ open class SpinnerInput(
override fun blur() {
getElementJQuery()?.blur()
}
+
+ override fun getState(): Number? = value
+
+ override fun subscribe(observer: (Number?) -> Unit): () -> Unit {
+ observers += observer
+ observer(value)
+ return {
+ observers -= observer
+ }
+ }
}
/**