aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/pl/treksoft/kvision/form/text
diff options
context:
space:
mode:
authorRobert Jaros <rjaros@finn.pl>2018-03-26 09:34:38 +0200
committerRobert Jaros <rjaros@finn.pl>2018-03-26 09:41:24 +0200
commit6287ce18301d58792e803bc7daa7068c164e704d (patch)
treecf90971cb887e8f16317f5b795bd5825b3bde29e /src/main/kotlin/pl/treksoft/kvision/form/text
parent3b1eae9ed8b7e1d57f8f05968820c5eb4bbe8fe2 (diff)
downloadkvision-6287ce18301d58792e803bc7daa7068c164e704d.tar.gz
kvision-6287ce18301d58792e803bc7daa7068c164e704d.tar.bz2
kvision-6287ce18301d58792e803bc7daa7068c164e704d.zip
Plain HTML form attributes (method, action, enctype, target, ...) support.
Form controls refactoring.
Diffstat (limited to 'src/main/kotlin/pl/treksoft/kvision/form/text')
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/form/text/AbstractText.kt18
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/form/text/AbstractTextInput.kt9
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/form/text/Password.kt13
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/form/text/RichText.kt16
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/form/text/Text.kt12
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/form/text/TextArea.kt12
6 files changed, 42 insertions, 38 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 3c62d4a8..7c23615a 100644
--- a/src/main/kotlin/pl/treksoft/kvision/form/text/AbstractText.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/form/text/AbstractText.kt
@@ -67,14 +67,6 @@ abstract class AbstractText(label: String? = null, rich: Boolean = false) :
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
@@ -82,11 +74,6 @@ abstract class AbstractText(label: String? = null, rich: Boolean = false) :
set(value) {
input.maxlength = value
}
- override var disabled
- get() = input.disabled
- set(value) {
- input.disabled = value
- }
/**
* Determines if the text input is automatically focused.
*/
@@ -119,11 +106,6 @@ abstract class AbstractText(label: String? = null, rich: Boolean = false) :
set(value) {
flabel.rich = value
}
- override var size
- get() = input.size
- set(value) {
- input.size = value
- }
/**
* @suppress
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 5f4a243d..52cc7792 100644
--- a/src/main/kotlin/pl/treksoft/kvision/form/text/AbstractTextInput.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/form/text/AbstractTextInput.kt
@@ -25,6 +25,7 @@ import com.github.snabbdom.VNode
import pl.treksoft.kvision.core.StringBoolPair
import pl.treksoft.kvision.core.StringPair
import pl.treksoft.kvision.core.Widget
+import pl.treksoft.kvision.form.FormInput
import pl.treksoft.kvision.form.InputSize
/**
@@ -37,7 +38,7 @@ import pl.treksoft.kvision.form.InputSize
abstract class AbstractTextInput(
value: String? = null,
classes: Set<String> = setOf()
-) : Widget(classes) {
+) : Widget(classes), FormInput {
init {
this.setInternalEventListener<AbstractTextInput> {
@@ -65,7 +66,7 @@ abstract class AbstractTextInput(
/**
* The name attribute of the generated HTML input element.
*/
- var name: String? by refreshOnUpdate()
+ override var name: String? by refreshOnUpdate()
/**
* Maximal length of the text input value.
*/
@@ -73,7 +74,7 @@ abstract class AbstractTextInput(
/**
* Determines if the field is disabled.
*/
- var disabled by refreshOnUpdate(false)
+ override var disabled by refreshOnUpdate(false)
/**
* Determines if the text input is automatically focused.
*/
@@ -85,7 +86,7 @@ abstract class AbstractTextInput(
/**
* The size of the input.
*/
- var size: InputSize? by refreshOnUpdate()
+ override 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/Password.kt b/src/main/kotlin/pl/treksoft/kvision/form/text/Password.kt
index 995243c9..1d36516e 100644
--- a/src/main/kotlin/pl/treksoft/kvision/form/text/Password.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/form/text/Password.kt
@@ -28,12 +28,13 @@ import pl.treksoft.kvision.core.Container
*
* @constructor
* @param value text input value
+ * @param name the name attribute of the generated HTML input element
* @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(
+open class Password(value: String? = null, name: String? = null, label: String? = null, rich: Boolean = false) : Text(
TextInputType.PASSWORD,
- value, label, rich
+ value, name, label, rich
) {
companion object {
/**
@@ -42,9 +43,13 @@ open class Password(value: String? = null, label: String? = null, rich: Boolean
* It takes the same parameters as the constructor of the built component.
*/
fun Container.password(
- value: String? = null, label: String? = null, rich: Boolean = false, init: (Password.() -> Unit)? = null
+ value: String? = null,
+ name: String? = null,
+ label: String? = null,
+ rich: Boolean = false,
+ init: (Password.() -> Unit)? = null
): Password {
- val password = Password(value, label, rich).apply { init?.invoke(this) }
+ val password = Password(value, name, label, rich).apply { init?.invoke(this) }
this.add(password)
return password
}
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 953fec90..22126797 100644
--- a/src/main/kotlin/pl/treksoft/kvision/form/text/RichText.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/form/text/RichText.kt
@@ -28,11 +28,12 @@ import pl.treksoft.kvision.core.Container
*
* @constructor
* @param value text input value
+ * @param name the name attribute of the generated HTML input element
* @param label label text bound to the input element
* @param rich determines if [label] can contain HTML code
*/
open class RichText(
- value: String? = null,
+ value: String? = null, name: String? = null,
label: String? = null, rich: Boolean = false
) : AbstractText(label, rich) {
@@ -45,7 +46,10 @@ open class RichText(
input.height = value
}
- final override val input: RichTextInput = RichTextInput(value).apply { id = idc }
+ final override val input: RichTextInput = RichTextInput(value).apply {
+ this.id = idc
+ this.name = name
+ }
init {
@Suppress("LeakingThis")
@@ -61,9 +65,13 @@ open class RichText(
* It takes the same parameters as the constructor of the built component.
*/
fun Container.richText(
- value: String? = null, label: String? = null, rich: Boolean = false, init: (RichText.() -> Unit)? = null
+ value: String? = null,
+ name: String? = null,
+ label: String? = null,
+ rich: Boolean = false,
+ init: (RichText.() -> Unit)? = null
): RichText {
- val richText = RichText(value, label, rich).apply { init?.invoke(this) }
+ val richText = RichText(value, name, label, rich).apply { init?.invoke(this) }
this.add(richText)
return richText
}
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 fd53adff..7e4127f5 100644
--- a/src/main/kotlin/pl/treksoft/kvision/form/text/Text.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/form/text/Text.kt
@@ -29,11 +29,12 @@ import pl.treksoft.kvision.core.Container
* @constructor
* @param type text input type (default "text")
* @param value text input value
+ * @param name the name attribute of the generated HTML input element
* @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,
+ type: TextInputType = TextInputType.TEXT, value: String? = null, name: String? = null,
label: String? = null, rich: Boolean = false
) : AbstractText(label, rich) {
@@ -54,7 +55,10 @@ open class Text(
input.autocomplete = value
}
- final override val input: TextInput = TextInput(type, value).apply { id = idc }
+ final override val input: TextInput = TextInput(type, value).apply {
+ this.id = idc
+ this.name = name
+ }
init {
@Suppress("LeakingThis")
@@ -70,10 +74,10 @@ open class Text(
* It takes the same parameters as the constructor of the built component.
*/
fun Container.text(
- type: TextInputType = TextInputType.TEXT, value: String? = null,
+ type: TextInputType = TextInputType.TEXT, value: String? = null, name: String? = null,
label: String? = null, rich: Boolean = false, init: (Text.() -> Unit)? = null
): Text {
- val text = Text(type, value, label, rich).apply { init?.invoke(this) }
+ val text = Text(type, value, name, label, rich).apply { init?.invoke(this) }
this.add(text)
return text
}
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 58f63028..d5058583 100644
--- a/src/main/kotlin/pl/treksoft/kvision/form/text/TextArea.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/form/text/TextArea.kt
@@ -30,11 +30,12 @@ import pl.treksoft.kvision.core.Container
* @param cols number of columns
* @param rows number of rows
* @param value text input value
+ * @param name the name attribute of the generated HTML input element
* @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,
+ cols: Int? = null, rows: Int? = null, value: String? = null, name: String? = null,
label: String? = null, rich: Boolean = false
) : AbstractText(label, rich) {
@@ -63,7 +64,10 @@ open class TextArea(
input.wrapHard = value
}
- final override val input: TextAreaInput = TextAreaInput(cols, rows, value).apply { id = idc }
+ final override val input: TextAreaInput = TextAreaInput(cols, rows, value).apply {
+ this.id = idc
+ this.name = name
+ }
init {
@Suppress("LeakingThis")
@@ -79,10 +83,10 @@ open class TextArea(
* It takes the same parameters as the constructor of the built component.
*/
fun Container.textArea(
- cols: Int? = null, rows: Int? = null, value: String? = null,
+ cols: Int? = null, rows: Int? = null, value: String? = null, name: String? = null,
label: String? = null, rich: Boolean = false, init: (TextArea.() -> Unit)? = null
): TextArea {
- val textArea = TextArea(cols, rows, value, label, rich).apply { init?.invoke(this) }
+ val textArea = TextArea(cols, rows, value, name, label, rich).apply { init?.invoke(this) }
this.add(textArea)
return textArea
}