aboutsummaryrefslogtreecommitdiff
path: root/kvision-modules/kvision-spinner/src/main
diff options
context:
space:
mode:
authorRobert Jaros <rjaros@finn.pl>2019-01-17 13:41:57 +0100
committerRobert Jaros <rjaros@finn.pl>2019-01-17 13:41:57 +0100
commitf246fff378ae162204cd64ec6ae6038afe369688 (patch)
tree43327cd48ae9f8f63522e53a69f6a769441d04c9 /kvision-modules/kvision-spinner/src/main
parenta65fc998b69fbcb64809fa7d4cf95b777ecec145 (diff)
downloadkvision-f246fff378ae162204cd64ec6ae6038afe369688.tar.gz
kvision-f246fff378ae162204cd64ec6ae6038afe369688.tar.bz2
kvision-f246fff378ae162204cd64ec6ae6038afe369688.zip
Upgrade of touchspin component and removed default limits.
Diffstat (limited to 'kvision-modules/kvision-spinner/src/main')
-rw-r--r--kvision-modules/kvision-spinner/src/main/kotlin/pl/treksoft/kvision/form/spinner/Spinner.kt10
-rw-r--r--kvision-modules/kvision-spinner/src/main/kotlin/pl/treksoft/kvision/form/spinner/SpinnerInput.kt22
2 files changed, 19 insertions, 13 deletions
diff --git a/kvision-modules/kvision-spinner/src/main/kotlin/pl/treksoft/kvision/form/spinner/Spinner.kt b/kvision-modules/kvision-spinner/src/main/kotlin/pl/treksoft/kvision/form/spinner/Spinner.kt
index 4fa68e47..31c6ceb8 100644
--- a/kvision-modules/kvision-spinner/src/main/kotlin/pl/treksoft/kvision/form/spinner/Spinner.kt
+++ b/kvision-modules/kvision-spinner/src/main/kotlin/pl/treksoft/kvision/form/spinner/Spinner.kt
@@ -36,8 +36,8 @@ 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 min minimal value
+ * @param max maximal value
* @param step step value (default 1)
* @param decimals number of decimal digits (default 0)
* @param buttonsType spinner buttons type
@@ -46,7 +46,7 @@ import pl.treksoft.kvision.utils.SnOn
* @param rich determines if [label] can contain HTML code
*/
open class Spinner(
- value: Number? = null, name: String? = null, min: Int = 0, max: Int = DEFAULT_MAX, step: Double = DEFAULT_STEP,
+ value: Number? = null, name: String? = null, min: Int? = null, max: Int? = null, step: Double = DEFAULT_STEP,
decimals: Int = 0, buttonsType: ButtonsType = ButtonsType.VERTICAL,
forceType: ForceType = ForceType.NONE, label: String? = null,
rich: Boolean = false
@@ -241,8 +241,8 @@ open class Spinner(
fun Container.spinner(
value: Number? = null,
name: String? = null,
- min: Int = 0,
- max: Int = DEFAULT_MAX,
+ min: Int? = null,
+ max: Int? = null,
step: Double = DEFAULT_STEP,
decimals: Int = 0,
buttonsType: ButtonsType = ButtonsType.VERTICAL,
diff --git a/kvision-modules/kvision-spinner/src/main/kotlin/pl/treksoft/kvision/form/spinner/SpinnerInput.kt b/kvision-modules/kvision-spinner/src/main/kotlin/pl/treksoft/kvision/form/spinner/SpinnerInput.kt
index b4a8138a..5fc7470a 100644
--- a/kvision-modules/kvision-spinner/src/main/kotlin/pl/treksoft/kvision/form/spinner/SpinnerInput.kt
+++ b/kvision-modules/kvision-spinner/src/main/kotlin/pl/treksoft/kvision/form/spinner/SpinnerInput.kt
@@ -51,15 +51,14 @@ enum class ForceType(internal val value: String) {
}
internal const val DEFAULT_STEP = 1.0
-internal const val DEFAULT_MAX = 100
/**
* The basic component for spinner control.
*
* @constructor
* @param value spinner value
- * @param min minimal value (default 0)
- * @param max maximal value (default 100)
+ * @param min minimal value
+ * @param max maximal value
* @param step step value (default 1)
* @param decimals number of decimal digits (default 0)
* @param buttonsType spinner buttons type
@@ -68,7 +67,7 @@ internal const val DEFAULT_MAX = 100
*/
@Suppress("TooManyFunctions")
open class SpinnerInput(
- value: Number? = null, min: Int = 0, max: Int = DEFAULT_MAX, step: Double = DEFAULT_STEP,
+ value: Number? = null, min: Int? = null, max: Int? = null, step: Double = DEFAULT_STEP,
decimals: Int = 0, buttonsType: ButtonsType = ButtonsType.VERTICAL,
forceType: ForceType = ForceType.NONE,
classes: Set<String> = setOf()
@@ -205,6 +204,10 @@ open class SpinnerInput(
val v = getElementJQuery()?.`val`() as String?
if (v != null && v.isNotEmpty()) {
this.value = v.toDoubleOrNull()
+ this.value?.let {
+ if (min != null && it.toInt() < min ?: 0) this.value = min
+ if (max != null && it.toInt() > max ?: 0) this.value = max
+ }
} else {
this.value = null
}
@@ -214,9 +217,6 @@ open class SpinnerInput(
override fun afterInsert(node: VNode) {
getElementJQueryD()?.TouchSpin(getSettingsObj())
siblings = getElementJQuery()?.parent(".bootstrap-touchspin")?.children("span")
- size?.let {
- siblings?.find("button")?.addClass(it.className)
- }
this.getElementJQuery()?.on("change") { e, _ ->
if (e.asDynamic().isTrigger != null) {
val event = org.w3c.dom.events.Event("change")
@@ -280,6 +280,12 @@ open class SpinnerInput(
this.decimals = decimals
this.verticalbuttons = verticalbuttons
this.forcestepdivisibility = forceType.value
+ if (verticalbuttons) {
+ this.verticalup = "<i class=\"fa fa-caret-up\"></i>"
+ this.verticaldown = "<i class=\"fa fa-caret-down\"></i>"
+ }
+ this.buttondown_class = "btn btn-default"
+ this.buttonup_class = "btn btn-default"
}
}
@@ -306,7 +312,7 @@ open class SpinnerInput(
* It takes the same parameters as the constructor of the built component.
*/
fun Container.spinnerInput(
- value: Number? = null, min: Int = 0, max: Int = DEFAULT_MAX, step: Double = DEFAULT_STEP,
+ value: Number? = null, min: Int? = null, max: Int? = null, step: Double = DEFAULT_STEP,
decimals: Int = 0, buttonsType: ButtonsType = ButtonsType.VERTICAL,
forceType: ForceType = ForceType.NONE, classes: Set<String> = setOf(),
init: (SpinnerInput.() -> Unit)? = null