vue-checkbox-radio
vue-checkbox-radio copied to clipboard
When we do not specify value attribute, an empty string is sent to a server
When we use a plain checkbox element, we do not need to explicitly provide a value attribute. When checkbox is checked, a "on" value is sent to the server on form submit.
For this component, the value attribute must be specified, otherwise internally the component provides its <input type="checkbox"> with an empty value attribute. And therefore, when checkbox is checked, an empty value is sent to a server on form submit.
I spent a lot of time figuring out what's wrong.
I think that if no value specified for the component from outside, the component shouldn't add the value attribute to the internal <input type="checkbox"> element at all. In this case, browser will sent "on" to the server natively.
The default value is "on" for checkbox as well as radio:
- https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox#Value
- https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/radio#Data_representation_of_a_radio_group
Thank you, I'll check out but I need some time.
No problem. For your convenience:
https://github.com/mariomka/vue-checkbox-radio/blob/master/src/components/Checkbox.vue#L94 and https://github.com/mariomka/vue-checkbox-radio/blob/master/src/components/Radio.vue#L91
default: 'on' solves this issue.