yields / submittable

check if the given form element is submittable.
1 stars 1 forks source link

why are unchecked checkboxes not submittable? #1

Open stephenmathieson opened 10 years ago

stephenmathieson commented 10 years ago

i'm doing this to compensate and it just seems wrong:

var data = serialize.object(form)
data.checkboxthing = data.checkboxthing || false
dominicbarnes commented 10 years ago

Fwiw, the HTML5 spec calls for unchecked elements to be skipped altogether when constructing the dataset. I think it would be good to mimic this behavior, as it's already defined and probably expected by most users/developers.

yields commented 10 years ago

is there any case where someone would want unchecked elements to be skipped ? +1 to setting false when they are unchecked just cuz doying || false is a PITA.

dominicbarnes commented 10 years ago

afaik, the recommended way to approach this is to have 2 inputs:

<input type="hidden" name="check" value="false">
<input type="checkbox" name="check" value="true">

If the checkbox is checked, true will clobber the false. When unchecked, false shows through instead.

dominicbarnes commented 10 years ago

(that's how my form serialize library will handle this in my upcoming version anyways)

stephenmathieson commented 10 years ago

here's my use case:

if the second checkbox isn't submitted, then how do i know a user doesn't want to display things that don't matter to anyone?

i've already deployed with || false, so i'm not terribly worried about it, but it'd be nice to clean up some of that garbage in a future iteration.

stephenmathieson commented 9 years ago

@yields any thoughts on default behaviour here?

yields commented 9 years ago

sounds right to me :)