From 6287ce18301d58792e803bc7daa7068c164e704d Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Mon, 26 Mar 2018 09:34:38 +0200 Subject: Plain HTML form attributes (method, action, enctype, target, ...) support. Form controls refactoring. --- src/main/kotlin/pl/treksoft/kvision/html/Button.kt | 28 ++++++++++++++++++---- src/main/kotlin/pl/treksoft/kvision/html/Tag.kt | 3 ++- 2 files changed, 25 insertions(+), 6 deletions(-) (limited to 'src/main/kotlin/pl/treksoft/kvision/html') 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 @@ -51,6 +51,15 @@ enum class ButtonSize(internal val className: String) { XSMALL("btn-xs") } +/** + * Button types. + */ +enum class ButtonType(internal val buttonType: String) { + BUTTON("button"), + SUBMIT("submit"), + RESET("reset") +} + /** * Button component. * @@ -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 = setOf() ) : Widget(classes) { @@ -78,6 +87,10 @@ open class Button( * Button style. */ var style by refreshOnUpdate(style) + /** + * Button types. + */ + var type by refreshOnUpdate(type) /** * Determines if button is disabled. */ @@ -117,7 +130,7 @@ open class Button( } override fun getSnAttrs(): List { - 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 = setOf(), init: (Button.() -> Unit)? = null + text: String, + icon: String? = null, + style: ButtonStyle = ButtonStyle.DEFAULT, + type: ButtonType = ButtonType.BUTTON, + disabled: Boolean = false, + classes: Set = 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") } /** -- cgit