Rails 4 app with Bootstrap 3
I have a form that includes inputs from radio buttons:
<strong> Radio button options on form </strong><br>
   <div class="form-group">
      <%= f.radio_button :category, 'A' %>   <%= f.label "A", "A" %><br /> 
      <%= f.radio_button :category, 'B' %>   <%= f.label "B", "B" %><br />  
      <%= f.radio_button :category, 'C' %>   <%= f.label "C", "C" %><br />
   </div>
The first time the form is loaded, everything looks correct:

My issue is that if the form fails due to a validation error (missing required input, etc, anywhere on the form), when the page re-renders, the radio button and the label are displaying on two different lines:

How do I fix this issue?
Updated The generated HTML for each is: Original (correct):
    <strong> Radio button options on form </strong><br>
    <div class="form-group">
       <input id="listing_category_1" name="listing[category]" type="radio" value="1" />   <label for="listing_1">A</label><br /> 
       <input id="listing_category_2" name="listing[category]" type="radio" value="2" />   <label for="listing_2">B</label><br />  
       <input id="listing_category_3" name="listing[category]" type="radio" value="3" />   <label for="listing_3">C</label><br />
    </div>
And for the re-rendering (incorrect):
    <strong> Radio button options on form </strong><br>
    <div class="form-group">
       <div class="field_with_errors"><input id="listing_category_1" name="listing[category]" type="radio" value="1" /></div>   <label for="listing_1">A</label><br /> 
       <div class="field_with_errors"><input id="listing_category_2" name="listing[category]" type="radio" value="2" /></div>   <label for="listing_2">B</label><br />  
       <div class="field_with_errors"><input id="listing_category_3" name="listing[category]" type="radio" value="3" /></div>   <label for="listing_3">C</label><br />
    </div>
                This is because Rails wrap fields with errors into a div:
<div class="field_with_errors">
  <input name="foo" type="radio" value="1" />
</div>
One way to solve could be customize this css class, for example making div display property inline instead of block:
.field_with_errors { display: inline; }
Another option, modify Rails setting to change default behaviour when displaying errors:
config.action_view.field_error_proc = Proc.new { |html_tag, instance| "<span class='field_with_errors'>#{html_tag}</span>".html_safe }
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With