diff options
| author | Robert Jaros <rjaros@finn.pl> | 2018-02-09 01:23:34 +0100 |
|---|---|---|
| committer | Robert Jaros <rjaros@finn.pl> | 2018-02-09 01:23:34 +0100 |
| commit | d8779ac38742fe86d2489e47f5c8c4479ab74ba6 (patch) | |
| tree | f0895c0dfc9d5452cd67facc42bffc1554b17d16 /src/main/kotlin/pl/treksoft/kvision/form/text | |
| parent | 70d2f14d4a34f841a3161482eec5d355cbd755f6 (diff) | |
| download | kvision-d8779ac38742fe86d2489e47f5c8c4479ab74ba6.tar.gz kvision-d8779ac38742fe86d2489e47f5c8c4479ab74ba6.tar.bz2 kvision-d8779ac38742fe86d2489e47f5c8c4479ab74ba6.zip | |
Refactoring. API documentation.
Diffstat (limited to 'src/main/kotlin/pl/treksoft/kvision/form/text')
9 files changed, 413 insertions, 11 deletions
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 a3c89514..26a88f1e 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/text/AbstractText.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/text/AbstractText.kt @@ -1,36 +1,82 @@ +/* + * Copyright (c) 2017-present Robert Jaros + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package pl.treksoft.kvision.form.text +import pl.treksoft.kvision.core.StringBoolPair import pl.treksoft.kvision.core.Widget import pl.treksoft.kvision.form.FieldLabel import pl.treksoft.kvision.form.HelpBlock import pl.treksoft.kvision.form.StringFormControl import pl.treksoft.kvision.panel.SimplePanel import pl.treksoft.kvision.utils.SnOn -import pl.treksoft.kvision.core.StringBoolPair +/** + * Base class for form field text components. + * + * @constructor + * @param label label text bound to the input element + * @param rich determines if [label] can contain HTML code + */ abstract class AbstractText(label: String? = null, rich: Boolean = false) : SimplePanel(setOf("form-group")), StringFormControl { + /** + * Text input value. + */ override var value get() = input.value set(value) { input.value = value } + /** + * 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 get() = input.startValue set(value) { input.startValue = value } + /** + * The placeholder for the text input. + */ var placeholder get() = input.placeholder set(value) { input.placeholder = value } + /** + * The name attribute of the generated HTML input element. + */ var name get() = input.name set(value) { input.name = value } + /** + * Maximal length of the text input value. + */ var maxlength get() = input.maxlength set(value) { @@ -41,21 +87,33 @@ abstract class AbstractText(label: String? = null, rich: Boolean = false) : set(value) { input.disabled = value } + /** + * Determines if the text input is automatically focused. + */ var autofocus get() = input.autofocus set(value) { input.autofocus = value } + /** + * Determines if the text input is read-only. + */ var readonly get() = input.readonly set(value) { input.readonly = value } + /** + * The label text bound to the text input element. + */ var label get() = flabel.text set(value) { flabel.text = value } + /** + * Determines if [label] can contain HTML code. + */ var rich get() = flabel.rich set(value) { @@ -67,6 +125,10 @@ abstract class AbstractText(label: String? = null, rich: Boolean = false) : input.size = value } + /** + * @suppress + * Internal property + */ protected val idc = "kv_form_text_" + counter abstract override val input: AbstractTextInput final override val flabel: FieldLabel = FieldLabel(idc, label, rich) @@ -78,7 +140,7 @@ abstract class AbstractText(label: String? = null, rich: Boolean = false) : } companion object { - var counter = 0 + internal var counter = 0 } override fun getSnClass(): List<StringBoolPair> { @@ -104,4 +166,18 @@ abstract class AbstractText(label: String? = null, rich: Boolean = false) : input.removeEventListeners() return this } + + /** + * Makes the input element focused. + */ + open fun focus() { + input.focus() + } + + /** + * Makes the input element blur. + */ + open fun blur() { + input.blur() + } } 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 95a5d98b..17a6689b 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/text/AbstractTextInput.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/text/AbstractTextInput.kt @@ -1,11 +1,39 @@ +/* + * Copyright (c) 2017-present Robert Jaros + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package pl.treksoft.kvision.form.text import com.github.snabbdom.VNode -import pl.treksoft.kvision.core.Widget -import pl.treksoft.kvision.form.INPUTSIZE import pl.treksoft.kvision.core.StringBoolPair import pl.treksoft.kvision.core.StringPair +import pl.treksoft.kvision.core.Widget +import pl.treksoft.kvision.form.INPUTSIZE +/** + * Base class for basic text components. + * + * @constructor + * @param value text input value + * @param classes a set of CSS class names + */ abstract class AbstractTextInput( value: String? = null, classes: Set<String> = setOf() @@ -19,47 +47,77 @@ abstract class AbstractTextInput( } } + /** + * Text input value. + */ var value: String? = value set(value) { field = 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() } + /** + * The placeholder for the text input. + */ var placeholder: String? = null set(value) { field = value refresh() } + /** + * The name attribute of the generated HTML input element. + */ var name: String? = null set(value) { field = value refresh() } + /** + * Maximal length of the text input value. + */ var maxlength: Int? = null set(value) { field = value refresh() } + /** + * Determines if the field is disabled. + */ var disabled: Boolean = false set(value) { field = value refresh() } + /** + * Determines if the text input is automatically focused. + */ var autofocus: Boolean? = null set(value) { field = value refresh() } + /** + * Determines if the text input is read-only. + */ var readonly: Boolean? = null set(value) { field = value refresh() } + /** + * The size of the input. + */ var size: INPUTSIZE? = null set(value) { field = value @@ -105,12 +163,20 @@ abstract class AbstractTextInput( refreshState() } + /** + * @suppress + * Internal function + */ protected open fun refreshState() { value?.let { getElementJQuery()?.`val`(it) } ?: getElementJQueryD()?.`val`(null) } + /** + * @suppress + * Internal function + */ protected open fun changeValue() { val v = getElementJQuery()?.`val`() as String? if (v != null && v.isNotEmpty()) { @@ -119,4 +185,18 @@ abstract class AbstractTextInput( this.value = null } } + + /** + * Makes the input element focused. + */ + open fun focus() { + getElementJQuery()?.focus() + } + + /** + * Makes the input element blur. + */ + open fun blur() { + getElementJQuery()?.blur() + } } diff --git a/src/main/kotlin/pl/treksoft/kvision/form/text/Password.kt b/src/main/kotlin/pl/treksoft/kvision/form/text/Password.kt index cbdd7adf..f3f50a63 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/text/Password.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/text/Password.kt @@ -1,5 +1,34 @@ +/* + * Copyright (c) 2017-present Robert Jaros + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package pl.treksoft.kvision.form.text +/** + * Form field password component. + * + * @constructor + * @param value text input value + * @param label label text bound to the input element + * @param rich determines if [label] can contain HTML code + */ open class Password(value: String? = null, label: String? = null, rich: Boolean = false) : Text( TEXTINPUTTYPE.PASSWORD, value, label, rich diff --git a/src/main/kotlin/pl/treksoft/kvision/form/text/RichText.kt b/src/main/kotlin/pl/treksoft/kvision/form/text/RichText.kt index 6e1f8929..39083577 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/text/RichText.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/text/RichText.kt @@ -1,10 +1,42 @@ +/* + * Copyright (c) 2017-present Robert Jaros + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package pl.treksoft.kvision.form.text +/** + * Form field rich text component. + * + * @constructor + * @param value text input value + * @param label label text bound to the input element + * @param rich determines if [label] can contain HTML code + */ open class RichText( value: String? = null, label: String? = null, rich: Boolean = false ) : AbstractText(label, rich) { + /** + * Rich input control height. + */ var inputHeight get() = input.height set(value) { diff --git a/src/main/kotlin/pl/treksoft/kvision/form/text/RichTextInput.kt b/src/main/kotlin/pl/treksoft/kvision/form/text/RichTextInput.kt index 9df58266..ffdcc045 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/text/RichTextInput.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/text/RichTextInput.kt @@ -1,3 +1,24 @@ +/* + * Copyright (c) 2017-present Robert Jaros + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package pl.treksoft.kvision.form.text import com.github.snabbdom.VNode @@ -5,13 +26,20 @@ import pl.treksoft.jquery.jQuery import pl.treksoft.kvision.core.StringPair import kotlin.browser.document +/** + * Basic rich text component. + * + * @constructor + * @param value text input value + * @param classes a set of CSS class names + */ open class RichTextInput(value: String? = null, classes: Set<String> = setOf()) : AbstractTextInput(value, classes + "form-control" + "trix-control") { private var trixId: String? = null override fun render(): VNode { - return kvh("trix-editor") + return render("trix-editor") } override fun getSnAttrs(): List<StringPair> { diff --git a/src/main/kotlin/pl/treksoft/kvision/form/text/Text.kt b/src/main/kotlin/pl/treksoft/kvision/form/text/Text.kt index a17c1b5d..298a3209 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/text/Text.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/text/Text.kt @@ -1,16 +1,51 @@ +/* + * Copyright (c) 2017-present Robert Jaros + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package pl.treksoft.kvision.form.text - +/** + * Form field text component. + * + * @constructor + * @param type text input type (default "text") + * @param value text input value + * @param label label text bound to the input element + * @param rich determines if [label] can contain HTML code + */ open class Text( type: TEXTINPUTTYPE = TEXTINPUTTYPE.TEXT, value: String? = null, label: String? = null, rich: Boolean = false ) : AbstractText(label, rich) { + /** + * Text input type. + */ var type get() = input.type set(value) { input.type = value } + /** + * Determines if autocomplete is enabled for the input element. + */ var autocomplete get() = input.autocomplete set(value) { diff --git a/src/main/kotlin/pl/treksoft/kvision/form/text/TextArea.kt b/src/main/kotlin/pl/treksoft/kvision/form/text/TextArea.kt index e45d990d..02a64136 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/text/TextArea.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/text/TextArea.kt @@ -1,20 +1,60 @@ +/* + * Copyright (c) 2017-present Robert Jaros + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package pl.treksoft.kvision.form.text +/** + * Form field textarea component. + * + * @constructor + * @param cols number of columns + * @param rows number of rows + * @param value text input value + * @param label label text bound to the input element + * @param rich determines if [label] can contain HTML code + */ open class TextArea( cols: Int? = null, rows: Int? = null, value: String? = null, label: String? = null, rich: Boolean = false ) : AbstractText(label, rich) { + /** + * Number of columns. + */ var cols get() = input.cols set(value) { input.cols = value } + /** + * Number of rows. + */ var rows get() = input.rows set(value) { input.rows = value } + /** + * Determines if hard wrapping is enabled for the textarea element. + */ var wrapHard get() = input.wrapHard set(value) { 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 8efe0318..fd42de9c 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/text/TextAreaInput.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/text/TextAreaInput.kt @@ -1,21 +1,60 @@ +/* + * Copyright (c) 2017-present Robert Jaros + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package pl.treksoft.kvision.form.text import com.github.snabbdom.VNode import pl.treksoft.kvision.core.StringPair +/** + * Basic textarea component. + * + * @constructor + * @param cols number of columns + * @param rows number of rows + * @param value text input value + * @param classes a set of CSS class names + */ open class TextAreaInput(cols: Int? = null, rows: Int? = null, value: String? = null, classes: Set<String> = setOf()) : AbstractTextInput(value, classes + "form-control") { + /** + * Number of columns. + */ var cols: Int? = cols set(value) { field = value refresh() } + /** + * Number of rows. + */ var rows: Int? = rows set(value) { field = value refresh() } + /** + * Determines if hard wrapping is enabled for the textarea element. + */ var wrapHard: Boolean = false set(value) { field = value @@ -24,8 +63,8 @@ open class TextAreaInput(cols: Int? = null, rows: Int? = null, value: String? = override fun render(): VNode { return startValue?.let { - kvh("textarea", arrayOf(it)) - } ?: kvh("textarea") + render("textarea", arrayOf(it)) + } ?: render("textarea") } override fun getSnAttrs(): List<StringPair> { 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 bd945590..72791239 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/text/TextInput.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/text/TextInput.kt @@ -1,21 +1,64 @@ +/* + * Copyright (c) 2017-present Robert Jaros + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package pl.treksoft.kvision.form.text import com.github.snabbdom.VNode import pl.treksoft.kvision.core.StringPair -enum class TEXTINPUTTYPE(val type: String) { +/** + * Text input types. + */ +enum class TEXTINPUTTYPE(internal val type: String) { TEXT("text"), - PASSWORD("password") + PASSWORD("password"), + EMAIL("email"), + TEL("tel"), + COLOR("color"), + SEARCH("search"), + URL("url") } +/** + * Basic text component. + * + * @constructor + * @param type text input type (default "text") + * @param value text input value + * @param classes a set of CSS class names + */ open class TextInput(type: TEXTINPUTTYPE = TEXTINPUTTYPE.TEXT, value: String? = null, classes: Set<String> = setOf()) : AbstractTextInput(value, classes + "form-control") { + /** + * Text input type. + */ var type: TEXTINPUTTYPE = type set(value) { field = value refresh() } + /** + * Determines if autocomplete is enabled for the input element. + */ var autocomplete: Boolean? = null set(value) { field = value @@ -23,7 +66,7 @@ open class TextInput(type: TEXTINPUTTYPE = TEXTINPUTTYPE.TEXT, value: String? = } override fun render(): VNode { - return kvh("input") + return render("input") } override fun getSnAttrs(): List<StringPair> { |
