plataformatec/simple_form — Issue #428: Grouped collection check boxes
Author: semaperepelitsa
Created: 2012-02-02 21:23:27+00:00
State: open

I noticed you merged a pull request with grouped collection input, cool. Recently, I needed grouped collection check boxes in my application so that you get something like this:

**CIty** - input label
USA - group label
x New York - checkbox named `city_id` with value and label
x Las Vegas

Russia
x Moscow
x St. Petersburg

I have implemented a `grouped_collection_check_boxes` helper method that takes the same arguments as `grouped_collection_select` but renders multiple SimpleForm's collection inputs (as check boxes). This is much like `collection_select` and `collection_check_boxes`.

```ruby

require "simple_form"

module GroupedCollectionCheckBoxes
def grouped_collection_check_boxes(attribute, collection, group_method, group_label_method,
option_key_method, option_value_method, options = {}, html_options = {})
collection.inject("".html_safe) do |html, group|
html << input(attribute, as: :check_boxes, label: group.send(group_label_method), collection: group.send(group_method), label_method: option_value_method, value_method: option_key_method)
end
end
end

SimpleForm::FormBuilder.send(:include, GroupedCollectionCheckBoxes)
```

So now we can call `send :"grouped_collection_#{input_type}"` and easily swap two. Do you think we can include this in Simple Form?