eachValidators.presence makes no sense for radio buttons
Closed this issue · 2 comments
I worked around this with
# fix the presence validator for radio buttons
judge.eachValidators.presence = (options, messages) ->
if $(@).is(':radio')
judge.closed(if $("[name=\"#{@.name}\"]:radio:checked").length then [] else [messages.blank])
else
judge.closed(if @value.length then [] else [messages.blank])
for now. It should probably be solved with a more generic value = (elem) -> submitted_field_value
function and then checking value(this)
instead of this.value.length
.
Interested in your use case for this – what kind of data model checks for the presence of a radio button value? Feels like something that a default value in the database would fix, but I can't really comment without knowing the specifics.
Sometimes required choice (no default) is more appropriate. Otherwise you
nudge people into a default that might be inappropriate for them. See the
book Thaler - Nudge for details.
Interested in your use case for this – what kind of data model checks for
the presence of a radio button value? Feels like something that a default
value in the database would fix, but I can't really comment without knowing
the specifics.—
Reply to this email directly or view it on GitHub
#33 (comment).