I’m writing a quiz application and I need to validate the radio button
reponses. I do not have the questions in a database, I just have forms
which contain “question1” and then I strip out the “question” portion
and just insert the number as the question’s id. So now I’m faced with
the dilemma of making sure the radio buttons are pressed.
Radio buttons do not show up in params if a button is not pressed, so I
don’t even get the 0 or 1 of check boxes. Is there an additional field
I can add the radio_button tag so that it reports something like
“not_checked” for which I can raise an error?
Xavier L. wrote:
Can’t you check for params[:radio_button_name].nil? in the controller?
Hi Xavier ~
One option is to set a default value, but probably not ideal. The next
option would be some JavaScript that executes prior to the form
submission.
~ Ben
Alex Y. wrote:
Xavier L. wrote:
Can’t you check for params[:radio_button_name].nil? in the controller?
I was afraid that would be my only option. It feels like a real hack.
When I have a quiz with upwards of a 60 questions, that’ll become a
pain.
Thanks for the help,
Xavier L.
you can create your own helper for that and the resulting view will not
be
any more complex than now
still, I struggle to understand how you could not at least use some file
for
questions even if you don’t have a database and simply loop through them