diff options
author | Robert Jaros <rjaros@finn.pl> | 2018-03-26 09:34:38 +0200 |
---|---|---|
committer | Robert Jaros <rjaros@finn.pl> | 2018-03-26 09:41:24 +0200 |
commit | 6287ce18301d58792e803bc7daa7068c164e704d (patch) | |
tree | cf90971cb887e8f16317f5b795bd5825b3bde29e /src/main/kotlin/pl/treksoft/kvision/html | |
parent | 3b1eae9ed8b7e1d57f8f05968820c5eb4bbe8fe2 (diff) | |
download | kvision-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/html')
-rw-r--r-- | src/main/kotlin/pl/treksoft/kvision/html/Button.kt | 28 | ||||
-rw-r--r-- | src/main/kotlin/pl/treksoft/kvision/html/Tag.kt | 3 |
2 files changed, 25 insertions, 6 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/html/Button.kt b/src/main/kotlin/pl/treksoft/kvision/html/Button.kt index 84f7c309..99f4ca13 100644 --- a/src/main/kotlin/pl/treksoft/kvision/html/Button.kt +++ b/src/main/kotlin/pl/treksoft/kvision/html/Button.kt @@ -52,6 +52,15 @@ enum class ButtonSize(internal val className: String) { } /** + * Button types. + */ +enum class ButtonType(internal val buttonType: String) { + BUTTON("button"), + SUBMIT("submit"), + RESET("reset") +} + +/** * Button component. * * @constructor @@ -62,7 +71,7 @@ enum class ButtonSize(internal val className: String) { * @param classes a set of CSS class names */ open class Button( - text: String, icon: String? = null, style: ButtonStyle = ButtonStyle.DEFAULT, + text: String, icon: String? = null, style: ButtonStyle = ButtonStyle.DEFAULT, type: ButtonType = ButtonType.BUTTON, disabled: Boolean = false, classes: Set<String> = setOf() ) : Widget(classes) { @@ -79,6 +88,10 @@ open class Button( */ var style by refreshOnUpdate(style) /** + * Button types. + */ + var type by refreshOnUpdate(type) + /** * Determines if button is disabled. */ var disabled by refreshOnUpdate(disabled) @@ -117,7 +130,7 @@ open class Button( } override fun getSnAttrs(): List<StringPair> { - return super.getSnAttrs() + ("type" to "button") + return super.getSnAttrs() + ("type" to type.buttonType) } /** @@ -139,10 +152,15 @@ open class Button( * It takes the same parameters as the constructor of the built component. */ fun Container.button( - text: String, icon: String? = null, style: ButtonStyle = ButtonStyle.DEFAULT, - disabled: Boolean = false, classes: Set<String> = setOf(), init: (Button.() -> Unit)? = null + text: String, + icon: String? = null, + style: ButtonStyle = ButtonStyle.DEFAULT, + type: ButtonType = ButtonType.BUTTON, + disabled: Boolean = false, + classes: Set<String> = setOf(), + init: (Button.() -> Unit)? = null ): Button { - val button = Button(text, icon, style, disabled, classes).apply { init?.invoke(this) } + val button = Button(text, icon, style, type, disabled, classes).apply { init?.invoke(this) } this.add(button) return button } diff --git a/src/main/kotlin/pl/treksoft/kvision/html/Tag.kt b/src/main/kotlin/pl/treksoft/kvision/html/Tag.kt index 936d7b89..75536b88 100644 --- a/src/main/kotlin/pl/treksoft/kvision/html/Tag.kt +++ b/src/main/kotlin/pl/treksoft/kvision/html/Tag.kt @@ -76,7 +76,8 @@ enum class TAG(internal val tagName: String) { TR("tr"), TD("td"), - FORM("form") + FORM("form"), + INPUT("input") } /** |