Keen-UI icon indicating copy to clipboard operation
Keen-UI copied to clipboard

UiSwitch: Submit value when not on

Open EmilMoe opened this issue 5 years ago • 3 comments

I'm missing a property for submittedFalseValue or something as now it's just ignored.

EmilMoe avatar Jan 06 '20 11:01 EmilMoe

https://stackoverflow.com/questions/1809494/post-unchecked-html-checkboxes

EmilMoe avatar Jan 06 '20 14:01 EmilMoe

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>?

JosephusPaye avatar Jan 08 '20 10:01 JosephusPaye

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>

EmilMoe avatar Jan 08 '20 11:01 EmilMoe