416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
|
# File 'lib/satis/forms/builder.rb', line 416
def collection_of(input_type, method, options = {})
form_builder_method, custom_class, input_builder_method = case input_type
when :radio_buttons then [:collection_radio_buttons,
"custom-radio", :radio_button]
when :check_boxes then [:collection_check_boxes,
"custom-checkbox", :check_box]
else raise 'Invalid input_type for collection_of, valid input_types are ":radio_buttons", ":check_boxes"'
end
options[:value_method] ||= :last
options[:text_method] ||= options[:label_method] || :first
form_group(method, options) do
safe_join [
(custom_label(method, options[:label], options) unless options[:label] == false),
(send(form_builder_method, method, options[:collection], options[:value_method],
options[:text_method]) do |b|
tag.div(class: "custom-control #{custom_class}") do
safe_join [
b.send(input_builder_method, options.fetch(:input_html, {}).merge(class: "custom-control-input")),
b.label(class: "custom-control-label")
]
end
end)
]
end
end
|