leo*_*nel 3 ruby ruby-on-rails formtastic twitter-bootstrap
我正在使用 Twitter Bootstrap。
我有以下代码...
<div class="row">
<div class="span5">
<%= f.input :is_authorized_to_leave_with_child %>
<%= f.input :is_emergency_contact %>
</div>
<div class="span5">
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
问题是,标签显示在左侧,复选框显示在右侧。Twitter Bootstrap 示例表单复选框部分的外观正好相反,请查看:http : //twitter.github.com/bootstrap/base-css.html#forms
复选框在右侧,标签在右侧。我怎么能这样显示呢?
从formtastic 2.x 开始,您可以使用该app/inputs/#{ input_name.underscore }_input.rb文件重新定义现有输入的行为。
的默认行为BooleanInput是:调用to_html方法,调用label_with_nested_checkbox,调用label_text_with_embedded_checkbox,创建以下布局:
<label>
<input />
</label>
Run Code Online (Sandbox Code Playgroud)
并使用这个逻辑:
check_box_html << "" << label_text
Run Code Online (Sandbox Code Playgroud)
因此,您需要做的就是app/inputs/boolean_input.rb使用以下代码创建一个文件:
class BooleanInput < Formtastic::Inputs::BooleanInput
def label_text_with_embedded_checkbox
label_text << "" << check_box_html
end
end
Run Code Online (Sandbox Code Playgroud)
并更改一个app/assets/formtastic-ie7.css文件,使该输入看起来更漂亮一点:
.formtastic .boolean label input {
left:-4px;
}
Run Code Online (Sandbox Code Playgroud)
这是它的样子:

| 归档时间: |
|
| 查看次数: |
2179 次 |
| 最近记录: |