vue-checkbox-radio icon indicating copy to clipboard operation
vue-checkbox-radio copied to clipboard

When we do not specify value attribute, an empty string is sent to a server

Open plashenkov opened this issue 7 years ago • 3 comments

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.

plashenkov avatar Dec 05 '17 16:12 plashenkov

The default value is "on" for checkbox as well as radio:

  1. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox#Value
  2. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/radio#Data_representation_of_a_radio_group

plashenkov avatar Dec 06 '17 10:12 plashenkov

Thank you, I'll check out but I need some time.

mariomka avatar Dec 10 '17 01:12 mariomka

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.

plashenkov avatar Dec 10 '17 01:12 plashenkov