aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/pl/treksoft/kvision/form/spinner
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/spinner
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/spinner')
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/form/spinner/Spinner.kt43
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/form/spinner/SpinnerInput.kt9
2 files changed, 23 insertions, 29 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/form/spinner/Spinner.kt b/src/main/kotlin/pl/treksoft/kvision/form/spinner/Spinner.kt
index 9d72f36b..4fa68e47 100644
--- a/src/main/kotlin/pl/treksoft/kvision/form/spinner/Spinner.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/form/spinner/Spinner.kt
@@ -35,6 +35,7 @@ import pl.treksoft.kvision.utils.SnOn
*
* @constructor
* @param value spinner value
+ * @param name the name attribute of the generated HTML input element
* @param min minimal value (default 0)
* @param max maximal value (default 100)
* @param step step value (default 1)
@@ -45,7 +46,7 @@ import pl.treksoft.kvision.utils.SnOn
* @param rich determines if [label] can contain HTML code
*/
open class Spinner(
- value: Number? = null, min: Int = 0, max: Int = DEFAULT_MAX, step: Double = DEFAULT_STEP,
+ value: Number? = null, name: String? = null, min: Int = 0, max: Int = DEFAULT_MAX, step: Double = DEFAULT_STEP,
decimals: Int = 0, buttonsType: ButtonsType = ButtonsType.VERTICAL,
forceType: ForceType = ForceType.NONE, label: String? = null,
rich: Boolean = false
@@ -127,19 +128,6 @@ open class Spinner(
input.placeholder = value
}
/**
- * The name attribute of the generated HTML input element.
- */
- var name
- get() = input.name
- set(value) {
- input.name = value
- }
- override var disabled
- get() = input.disabled
- set(value) {
- input.disabled = value
- }
- /**
* Determines if the spinner is automatically focused.
*/
var autofocus
@@ -171,15 +159,13 @@ open class Spinner(
set(value) {
flabel.rich = value
}
- override var size
- get() = input.size
- set(value) {
- input.size = value
- }
protected val idc = "kv_form_spinner_$counter"
final override val input: SpinnerInput = SpinnerInput(value, min, max, step, decimals, buttonsType, forceType)
- .apply { id = idc }
+ .apply {
+ this.id = idc
+ this.name = name
+ }
final override val flabel: FieldLabel = FieldLabel(idc, label, rich)
final override val validationInfo: HelpBlock = HelpBlock().apply { visible = false }
@@ -253,12 +239,19 @@ open class Spinner(
* It takes the same parameters as the constructor of the built component.
*/
fun Container.spinner(
- value: Number? = null, min: Int = 0, max: Int = DEFAULT_MAX, step: Double = DEFAULT_STEP,
- decimals: Int = 0, buttonsType: ButtonsType = ButtonsType.VERTICAL,
- forceType: ForceType = ForceType.NONE, label: String? = null,
- rich: Boolean = false, init: (Spinner.() -> Unit)? = null
+ value: Number? = null,
+ name: String? = null,
+ min: Int = 0,
+ max: Int = DEFAULT_MAX,
+ step: Double = DEFAULT_STEP,
+ decimals: Int = 0,
+ buttonsType: ButtonsType = ButtonsType.VERTICAL,
+ forceType: ForceType = ForceType.NONE,
+ label: String? = null,
+ rich: Boolean = false,
+ init: (Spinner.() -> Unit)? = null
): Spinner {
- val spinner = Spinner(value, min, max, step, decimals, buttonsType, forceType, label, rich).apply {
+ val spinner = Spinner(value, name, min, max, step, decimals, buttonsType, forceType, label, rich).apply {
init?.invoke(
this
)
diff --git a/src/main/kotlin/pl/treksoft/kvision/form/spinner/SpinnerInput.kt b/src/main/kotlin/pl/treksoft/kvision/form/spinner/SpinnerInput.kt
index b9903ff8..e318db35 100644
--- a/src/main/kotlin/pl/treksoft/kvision/form/spinner/SpinnerInput.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/form/spinner/SpinnerInput.kt
@@ -27,6 +27,7 @@ import pl.treksoft.kvision.core.Container
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
import pl.treksoft.kvision.utils.obj
@@ -71,7 +72,7 @@ open class SpinnerInput(
decimals: Int = 0, buttonsType: ButtonsType = ButtonsType.VERTICAL,
forceType: ForceType = ForceType.NONE,
classes: Set<String> = setOf()
-) : Widget(classes + "form-control") {
+) : Widget(classes + "form-control"), FormInput {
init {
this.addSurroundingCssClass("input-group")
@@ -136,11 +137,11 @@ open class SpinnerInput(
/**
* The name attribute of the generated HTML input element.
*/
- var name: String? by refreshOnUpdate()
+ override var name: String? by refreshOnUpdate()
/**
* Determines if the field is disabled.
*/
- var disabled by refreshOnUpdate(false)
+ override var disabled by refreshOnUpdate(false)
/**
* Determines if the spinner is automatically focused.
*/
@@ -152,7 +153,7 @@ open class SpinnerInput(
/**
* The size of the input.
*/
- var size: InputSize? by refreshOnUpdate()
+ override var size: InputSize? by refreshOnUpdate()
private var siblings: JQuery? = null