Keen-UI
Keen-UI copied to clipboard
UiSwitch: Submit value when not on
I'm missing a property for submittedFalseValue
or something as now it's just ignored.
https://stackoverflow.com/questions/1809494/post-unchecked-html-checkboxes
Yeah this is an issue I've faced myself. Would it be better solved though outside of Keen UI? E.g. add the hidden input as recommended in that StackOverflow answer next to the use of <ui-switch></ui-switch>
?
I am not sure. But the use case for me was that I expected to always submit a value so others might expect it too? The solution could be that submit-false-value
to only include it when explicit wanting to in order not to manipulate the semantics per default.
I have created a wrapper component which you are welcome to get inspirations from, it will always submit a value, either 1 or 0 as this is what works for my specific project:
<template>
<div>
<ui-switch
:name="name"
:label="label"
v-model="value"
true-value="1"
false-value="0"
submitted-value="1">
<slot></slot>
</ui-switch>
<input
v-if="value === '0'"
type="hidden"
:name="name"
value="0">
</div>
</template>