Ruby on rails 用于引导的简单表单单选/复选框按钮组
我的问题是,我试图将一组复选框格式化为一个按钮组()。我有它大部分工作,但我有两个问题Ruby on rails 用于引导的简单表单单选/复选框按钮组,ruby-on-rails,twitter-bootstrap-3,simple-form,ruby-on-rails-4.2,Ruby On Rails,Twitter Bootstrap 3,Simple Form,Ruby On Rails 4.2,我的问题是,我试图将一组复选框格式化为一个按钮组()。我有它大部分工作,但我有两个问题 嵌套标签 我真的很想在.btn组中添加data toggle=“buttons”,这样引导按钮就会自动工作 #app/inputs/bootstrap_check_box_button_group_input.rb 类BootstrapCheckBoxButtonGroupInput1, :item_wrapper_tag=>false, :collection\u wrapper\u tag=>“div”
#app/inputs/bootstrap_check_box_button_group_input.rb
类BootstrapCheckBoxButtonGroupInput1,
:item_wrapper_tag=>false,
:collection\u wrapper\u tag=>“div”,
:collection\u wrapper\u class=>“btn组添加数据切换clearfix”
}
return@builder.send(
“收集复选框”,
属性名称,
收集
价值计量法,
标签法,
iopts,
输入\u html\u选项,
&集合\u块\u用于\u嵌套\u布尔\u样式
)
结束
受保护的
def构建\嵌套\布尔\样式\项目\标记(集合\构建器)
#比伯
tag=String.new
标记Mb此项将帮助您或仅使用下拉列表
# app/inputs/bootstrap_check_box_button_group_input.rb
class BootstrapCheckBoxButtonGroupInput < SimpleForm::Inputs::CollectionCheckBoxesInput
# Creates a radio button set for use with Bootstrap btn group
def input
label_method, value_method = detect_collection_methods
iopts = {
:checked => 1,
:item_wrapper_tag => false,
:collection_wrapper_tag => 'div',
:collection_wrapper_class => 'btn-group add-data-toggle clearfix'
}
return @builder.send(
"collection_check_boxes",
attribute_name,
collection,
value_method,
label_method,
iopts,
input_html_options,
&collection_block_for_nested_boolean_style
)
end
protected
def build_nested_boolean_style_item_tag(collection_builder)
# byebug
tag = String.new
tag << collection_builder.label(class: 'btn btn-cc') { "#{collection_builder.check_box} #{collection_builder.text}".html_safe }
return tag.html_safe
end
end
# _form.html.erb
<%= form.input 'test', collection: 1..5, as: :bootstrap_check_box_button_group %>
<div class="form-group bootstrap_check_box_button_group optional test_test">
<label class="bootstrap_check_box_button_group optional control-label">Test</label>
<div class="btn-group add-data-toggle clearfix">
<label for="test_test_1">
<label class="btn btn-cc" for="test_test_1">
<input class="bootstrap_check_box_button_group optional" type="checkbox" value="1" checked="checked" name="test[test][]" id="test_test_1"> 1</label>
</label>
<label for="test_test_2">
<label class="btn btn-cc" for="test_test_2">
<input class="bootstrap_check_box_button_group optional" type="checkbox" value="2" name="test[test][]" id="test_test_2"> 2</label>
</label>
<label for="test_test_3">
<label class="btn btn-cc" for="test_test_3">
<input class="bootstrap_check_box_button_group optional" type="checkbox" value="3" name="test[test][]" id="test_test_3"> 3</label>
</label>
<label for="test_test_4">
<label class="btn btn-cc" for="test_test_4">
<input class="bootstrap_check_box_button_group optional" type="checkbox" value="4" name="test[test][]" id="test_test_4"> 4</label>
</label>
<label for="test_test_5">
<label class="btn btn-cc" for="test_test_5">
<input class="bootstrap_check_box_button_group optional" type="checkbox" value="5" name="test[test][]" id="test_test_5"> 5</label>
</label>
<input type="hidden" name="test[test][]" value="">
</div>
</div>
<div class="form-group bootstrap_check_box_button_group optional test_test">
<label class="bootstrap_check_box_button_group optional control-label">Test</label>
<div class="btn-group add-data-toggle clearfix">
<label class="btn btn-cc" for="test_test_1">
<input class="bootstrap_check_box_button_group optional" type="checkbox" value="1" checked="checked" name="test[test][]" id="test_test_1"> 1
</label>
<label class="btn btn-cc" for="test_test_2">
<input class="bootstrap_check_box_button_group optional" type="checkbox" value="2" checked="checked" name="test[test][]" id="test_test_2"> 2
</label>
<label class="btn btn-cc" for="test_test_3">
<input class="bootstrap_check_box_button_group optional" type="checkbox" value="3" checked="checked" name="test[test][]" id="test_test_3"> 3
</label>
<label class="btn btn-cc" for="test_test_4">
<input class="bootstrap_check_box_button_group optional" type="checkbox" value="4" checked="checked" name="test[test][]" id="test_test_4"> 4
</label>
<label class="btn btn-cc" for="test_test_5">
<input class="bootstrap_check_box_button_group optional" type="checkbox" value="5" checked="checked" name="test[test][]" id="test_test_5"> 5
</label>
<input type="hidden" name="test[test][]" value="">
</div>
</div>