【发布时间】:2014-04-08 05:24:28
【问题描述】:
带有 Bootstrap 3 的 Rails 4 应用
我有一个包含单选按钮输入的表单:
<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>
第一次加载表单时,一切看起来都是正确的:
我的问题是,如果表单由于验证错误(缺少所需的输入等,表单上的任何位置)而失败,当页面重新呈现时,单选按钮和标签将显示在两个不同的行上:
我该如何解决这个问题?
更新 为每个生成的 HTML 是: 原文(正确):
<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>
对于重新渲染(不正确):
<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>
【问题讨论】:
-
您可以为原始页面和验证页面添加生成的 HTML 和 CSS 吗?
-
使用浏览器的开发工具检查,确定标记或 CSS 是否已更改。根据上面的屏幕截图,我们无法为您执行此操作。
-
谢谢,用 HTML 更新
标签: html ruby-on-rails twitter-bootstrap radio-button