Note that there are some explanatory texts on larger screens.

plurals
  1. PORails custom form generator - radio button not in response parameters unless it has a value
    primarykey
    data
    text
    <p>Ok, I've been digging around and haven't found an answer to this. I have a pretty complex custom rails form generator application that renders pages, sections, &amp; surveys (forms) from a database. </p> <p>It does validation server side (haven't finished the javascript yet and want both types), and I have it working for all types of form input objects, except for radio buttons. Because I can't get it to submit radio buttons to show up in params when they are not checked. As opposed to just looking for radio buttons outside of the params, I'd like to find a way to check them in my response loop (if possible).</p> <p>I've seen <a href="https://stackoverflow.com/questions/9420374/radio-button-value-in-rails-form-for-not-being-part-of-paramsmodel">this suggestion</a> of binding it to the model to make sure it validates, but my questions are unique and therefore I don't have a model object I'm binding it to. </p> <p>My form is declared in one partial:</p> <pre><code>&lt;%= form_tag take_surveys_path, :id =&gt; "take_surveys_new", :method =&gt; :post do %&gt; </code></pre> <p>and my code for generating the radio button (part of a partial that looks at a question type field):</p> <pre><code>&lt;% when 'Radio Button' %&gt; &lt;% question.answers.each do |answer| %&gt; &lt;%= radio_button "response[#{question.id}]content", question.question_text, answer.value %&gt; &lt;%=answer.value%&gt; &lt;br /&gt; &lt;% end %&gt; &lt;% end %&gt; </code></pre> <p>I iterate over params in my "take_survey_controller" and then check each question to see if it's valid, which includes regex and required validation based on some attributes set in my question object: </p> <pre><code> params[:response].each do |question_id, answer| #find my questions and answers, call if item.valid? #do a bunch of saving and stuff... end end </code></pre> <p>but this never gets called for radio buttons because empty radio buttons don't post to the params. </p> <p>Any suggestions or help? Happy to share more code if needed.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload