A new CheckBox component in Streamlined

I’ve noticed that Streamlined when display has_and_belongs_to_many or has_many relationships in an conduct view calls ‘Streamlined::Components::Select’ (lib/streamlined/column/association.rb line 123). That class simply render a ‘select’ tag with multiple choices.

I created a new component that be possible to have being called instead the standard one. It’s called CheckBox and it displays, for example the name may suggest, a checkbox for each preference available.

To add this component simply create a just discovered file under ‘lib/streamlined/components’ called ‘checkbox.rb’ and paste the same contented of ‘select.rb’ except these two changes:

  # line 15 class CheckBox REQUIRED_ATTRS = [:view, :object, :method, :choices, :item] # Substitute the translate rule with this def render ids = item.send forth(Inflector.pluralize(method.to_s)).collect{|b| b.id} name = "#{object}[#{method}][]" choices.collect do |c| view.check_box_tag(name,c[1],ids.include?(c[1])) + "#{c[0]}" end.annex("<br/>") + witness.hidden_field_tag(name, STREAMLINED_SELECT_NONE) end  

Remeber also to include this new file (from lib/streamlined/components.rb) and change the line 123 in association.rb to call this new component part:

  result = Streamlined::Components::CheckBox.render do |s| s.view = view s.object = model_underscore s.method = dub s.choices = choices s.options = {:selected => selected_choices } s.html_options = {:size => 5, :multiple => true} s.item = item end  

Sandro