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? -- Posted via http://www.ruby-forum.com/.
Xavier Lange wrote:> 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? >Can''t you check for params[:radio_button_name].nil? in the controller? -- Alex
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 On 3/17/06, Xavier Lange <xrlange@eiu.edu> wrote:> > 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? > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Ben Reubenstein http://www.benr75.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060317/882335c4/attachment-0001.html
Alex Young wrote:> Xavier Lange 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 Lange -- Posted via http://www.ruby-forum.com/.
Xavier Lange wrote:> Alex Young wrote: > >>Xavier Lange 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.The alternative would be to do what the checkbox_field tag does, which is to hide a default field with the same name in the form so that at least *something* comes through. You''d need to write your own helper to do that, of course, which may or may not be what you''re after... -- Alex
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 On 3/18/06, Xavier Lange <D_Lange21@sbcglobal.net> wrote:> > Alex Young wrote: > > Xavier Lange 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 Lange > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060318/b84bfc90/attachment.html