JosephusPaye / Keen-UI

A lightweight Vue.js UI library with a simple API, inspired by Google's Material Design.
https://josephuspaye.github.io/Keen-UI/
MIT License
4.1k stars 438 forks source link

UiSwitch: Submit value when not on #485

Open EmilMoe opened 4 years ago

EmilMoe commented 4 years ago

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

EmilMoe commented 4 years ago

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

JosephusPaye commented 4 years ago

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

EmilMoe commented 4 years ago

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>