From 19906e0305e054c1d951705335a61d41949565f4 Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Thu, 8 Mar 2018 11:28:01 +0100 Subject: Add focus() and blur() methods to all FormControls. --- src/main/kotlin/pl/treksoft/kvision/form/FormControl.kt | 10 ++++++++++ src/main/kotlin/pl/treksoft/kvision/form/check/CheckBox.kt | 8 ++++++++ .../kotlin/pl/treksoft/kvision/form/check/CheckInput.kt | 14 ++++++++++++++ src/main/kotlin/pl/treksoft/kvision/form/check/Radio.kt | 8 ++++++++ .../kotlin/pl/treksoft/kvision/form/check/RadioGroup.kt | 8 ++++++++ src/main/kotlin/pl/treksoft/kvision/form/select/Select.kt | 8 ++++++++ .../kotlin/pl/treksoft/kvision/form/select/SelectInput.kt | 13 +++++++++++++ .../kotlin/pl/treksoft/kvision/form/spinner/Spinner.kt | 8 ++++++++ .../pl/treksoft/kvision/form/spinner/SpinnerInput.kt | 14 ++++++++++++++ .../kotlin/pl/treksoft/kvision/form/text/AbstractText.kt | 10 ++-------- src/main/kotlin/pl/treksoft/kvision/form/time/DateTime.kt | 8 ++++++++ .../kotlin/pl/treksoft/kvision/form/time/DateTimeInput.kt | 14 ++++++++++++++ 12 files changed, 115 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/pl/treksoft/kvision/form/FormControl.kt b/src/main/kotlin/pl/treksoft/kvision/form/FormControl.kt index 2b974379..b74ae533 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/FormControl.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/FormControl.kt @@ -92,6 +92,16 @@ interface FormControl : Component { validationInfo.visible = value != null refresh() } + + /** + * Makes the input element focused. + */ + fun focus() + + /** + * Makes the input element blur. + */ + fun blur() } /** diff --git a/src/main/kotlin/pl/treksoft/kvision/form/check/CheckBox.kt b/src/main/kotlin/pl/treksoft/kvision/form/check/CheckBox.kt index 80790bdd..f1d231c6 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/check/CheckBox.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/check/CheckBox.kt @@ -187,6 +187,14 @@ open class CheckBox( return this } + override fun focus() { + input.focus() + } + + override fun blur() { + input.blur() + } + companion object { internal var counter = 0 diff --git a/src/main/kotlin/pl/treksoft/kvision/form/check/CheckInput.kt b/src/main/kotlin/pl/treksoft/kvision/form/check/CheckInput.kt index a9e7b33d..0ed85e44 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/check/CheckInput.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/check/CheckInput.kt @@ -152,6 +152,20 @@ open class CheckInput( return this } + /** + * Makes the input element focused. + */ + open fun focus() { + getElementJQuery()?.focus() + } + + /** + * Makes the input element blur. + */ + open fun blur() { + getElementJQuery()?.blur() + } + companion object { /** * DSL builder extension function. diff --git a/src/main/kotlin/pl/treksoft/kvision/form/check/Radio.kt b/src/main/kotlin/pl/treksoft/kvision/form/check/Radio.kt index 31ad41a2..5b02938c 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/check/Radio.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/check/Radio.kt @@ -207,6 +207,14 @@ open class Radio( return this } + override fun focus() { + input.focus() + } + + override fun blur() { + input.blur() + } + companion object { internal var counter = 0 diff --git a/src/main/kotlin/pl/treksoft/kvision/form/check/RadioGroup.kt b/src/main/kotlin/pl/treksoft/kvision/form/check/RadioGroup.kt index 9a331b14..2ed8a36c 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/check/RadioGroup.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/check/RadioGroup.kt @@ -152,6 +152,14 @@ open class RadioGroup( this.addInternal(validationInfo) } + override fun focus() { + getChildren().filterIsInstance().firstOrNull()?.focus() + } + + override fun blur() { + getChildren().filterIsInstance().firstOrNull()?.blur() + } + companion object { internal var counter = 0 diff --git a/src/main/kotlin/pl/treksoft/kvision/form/select/Select.kt b/src/main/kotlin/pl/treksoft/kvision/form/select/Select.kt index 0e5c7693..8d443ecf 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/select/Select.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/select/Select.kt @@ -270,6 +270,14 @@ open class Select( input.toggleOptions() } + override fun focus() { + input.focus() + } + + override fun blur() { + input.blur() + } + companion object { internal var counter = 0 diff --git a/src/main/kotlin/pl/treksoft/kvision/form/select/SelectInput.kt b/src/main/kotlin/pl/treksoft/kvision/form/select/SelectInput.kt index e94d7e2f..87580139 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/select/SelectInput.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/select/SelectInput.kt @@ -329,6 +329,19 @@ open class SelectInput( } ?: getElementJQueryD()?.selectpicker("val", null) } + /** + * Makes the input element focused. + */ + open fun focus() { + getElementJQuery()?.focus() + } + + /** + * Makes the input element blur. + */ + open fun blur() { + getElementJQuery()?.blur() + } companion object { /** diff --git a/src/main/kotlin/pl/treksoft/kvision/form/spinner/Spinner.kt b/src/main/kotlin/pl/treksoft/kvision/form/spinner/Spinner.kt index c96bae26..0aa514b7 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/spinner/Spinner.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/spinner/Spinner.kt @@ -236,6 +236,14 @@ open class Spinner( return this } + override fun focus() { + input.focus() + } + + override fun blur() { + input.blur() + } + companion object { internal var counter = 0 diff --git a/src/main/kotlin/pl/treksoft/kvision/form/spinner/SpinnerInput.kt b/src/main/kotlin/pl/treksoft/kvision/form/spinner/SpinnerInput.kt index a0da7999..b9903ff8 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/spinner/SpinnerInput.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/spinner/SpinnerInput.kt @@ -281,6 +281,20 @@ open class SpinnerInput( } } + /** + * Makes the input element focused. + */ + open fun focus() { + getElementJQuery()?.focus() + } + + /** + * Makes the input element blur. + */ + open fun blur() { + getElementJQuery()?.blur() + } + companion object { internal var counter = 0 diff --git a/src/main/kotlin/pl/treksoft/kvision/form/text/AbstractText.kt b/src/main/kotlin/pl/treksoft/kvision/form/text/AbstractText.kt index c946af8c..1d3b5e01 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/text/AbstractText.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/text/AbstractText.kt @@ -167,17 +167,11 @@ abstract class AbstractText(label: String? = null, rich: Boolean = false) : return this } - /** - * Makes the input element focused. - */ - open fun focus() { + override fun focus() { input.focus() } - /** - * Makes the input element blur. - */ - open fun blur() { + override fun blur() { input.blur() } } 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 f8b77893..dd6f222d 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/time/DateTime.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/time/DateTime.kt @@ -232,6 +232,14 @@ open class DateTime( return input.getValueAsString() } + override fun focus() { + input.focus() + } + + override fun blur() { + input.blur() + } + companion object { internal var counter = 0 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 867a3aba..d935487b 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/time/DateTimeInput.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/time/DateTimeInput.kt @@ -248,6 +248,20 @@ open class DateTimeInput( return value?.toStringF(format) } + /** + * Makes the input element focused. + */ + open fun focus() { + getElementJQuery()?.focus() + } + + /** + * Makes the input element blur. + */ + open fun blur() { + getElementJQuery()?.blur() + } + companion object { private fun String.toDatePickerFormat(): String { return this.replace("YY", "yy").replace("m", "i").replace("MMMM", "{----}").replace("MMM", "{---}") -- cgit