diff options
author | Robert Jaros <rjaros@finn.pl> | 2018-02-22 12:43:43 +0100 |
---|---|---|
committer | Robert Jaros <rjaros@finn.pl> | 2018-02-22 12:43:43 +0100 |
commit | e40c13c62de806169368adc7c2c4212f7df6413b (patch) | |
tree | 250e39d407cd2c6ef19c9a8ea0176a3215a4a818 /src/main/kotlin/pl/treksoft/kvision/form/text | |
parent | 1aefed336f9ef305f59d3668abc8a39c550e921d (diff) | |
download | kvision-e40c13c62de806169368adc7c2c4212f7df6413b.tar.gz kvision-e40c13c62de806169368adc7c2c4212f7df6413b.tar.bz2 kvision-e40c13c62de806169368adc7c2c4212f7df6413b.zip |
Property values delegated to a map (idea by tieskedh)
Closes #2
Diffstat (limited to 'src/main/kotlin/pl/treksoft/kvision/form/text')
3 files changed, 14 insertions, 71 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/form/text/AbstractTextInput.kt b/src/main/kotlin/pl/treksoft/kvision/form/text/AbstractTextInput.kt index 17a6689b..8467dab8 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/text/AbstractTextInput.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/text/AbstractTextInput.kt @@ -50,79 +50,42 @@ abstract class AbstractTextInput( /** * Text input value. */ - var value: String? = value - set(value) { - field = value - refreshState() - } + var value by refreshOnUpdate(value, { refreshState() }) /** * The value attribute of the generated HTML input element. * * This value is placed directly in generated HTML code, while the [value] property is dynamically * bound to the text input value. */ - var startValue: String? = value - set(value) { - field = value - this.value = value - refresh() - } + var startValue by refreshOnUpdate(value, { this.value = it; refresh() }) /** * The placeholder for the text input. */ - var placeholder: String? = null - set(value) { - field = value - refresh() - } + var placeholder: String? by refreshOnUpdate() /** * The name attribute of the generated HTML input element. */ - var name: String? = null - set(value) { - field = value - refresh() - } + var name: String? by refreshOnUpdate() /** * Maximal length of the text input value. */ - var maxlength: Int? = null - set(value) { - field = value - refresh() - } + var maxlength: Int? by refreshOnUpdate() /** * Determines if the field is disabled. */ - var disabled: Boolean = false - set(value) { - field = value - refresh() - } + var disabled by refreshOnUpdate(false) /** * Determines if the text input is automatically focused. */ - var autofocus: Boolean? = null - set(value) { - field = value - refresh() - } + var autofocus: Boolean? by refreshOnUpdate() /** * Determines if the text input is read-only. */ - var readonly: Boolean? = null - set(value) { - field = value - refresh() - } + var readonly: Boolean? by refreshOnUpdate() /** * The size of the input. */ - var size: INPUTSIZE? = null - set(value) { - field = value - refresh() - } + var size: INPUTSIZE? by refreshOnUpdate() override fun getSnClass(): List<StringBoolPair> { val cl = super.getSnClass().toMutableList() diff --git a/src/main/kotlin/pl/treksoft/kvision/form/text/TextAreaInput.kt b/src/main/kotlin/pl/treksoft/kvision/form/text/TextAreaInput.kt index 8ee150e1..9fc89544 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/text/TextAreaInput.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/text/TextAreaInput.kt @@ -40,27 +40,15 @@ open class TextAreaInput(cols: Int? = null, rows: Int? = null, value: String? = /** * Number of columns. */ - var cols: Int? = cols - set(value) { - field = value - refresh() - } + var cols by refreshOnUpdate(cols) /** * Number of rows. */ - var rows: Int? = rows - set(value) { - field = value - refresh() - } + var rows by refreshOnUpdate(rows) /** * Determines if hard wrapping is enabled for the textarea element. */ - var wrapHard: Boolean = false - set(value) { - field = value - refresh() - } + var wrapHard by refreshOnUpdate(false) override fun render(): VNode { return startValue?.let { diff --git a/src/main/kotlin/pl/treksoft/kvision/form/text/TextInput.kt b/src/main/kotlin/pl/treksoft/kvision/form/text/TextInput.kt index a2bfcd0b..998bfb2c 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/text/TextInput.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/text/TextInput.kt @@ -52,19 +52,11 @@ open class TextInput(type: TEXTINPUTTYPE = TEXTINPUTTYPE.TEXT, value: String? = /** * Text input type. */ - var type: TEXTINPUTTYPE = type - set(value) { - field = value - refresh() - } + var type by refreshOnUpdate(type) /** * Determines if autocomplete is enabled for the input element. */ - var autocomplete: Boolean? = null - set(value) { - field = value - refresh() - } + var autocomplete: Boolean? by refreshOnUpdate() override fun render(): VNode { return render("input") |