Module: JqueryUiForm::Inputs::CheckBoxesInput
- Included in:
- FormBuilder
- Defined in:
- lib/jquery_ui_form/inputs/check_boxes_input.rb
Instance Method Summary collapse
- #check_boxes_input(method, options = {}) ⇒ Object
- #collection_from_association(method) ⇒ Object
- #current_values_from_association(method) ⇒ Object
- #label_from_association(row, label_method) ⇒ Object
- #value_from_association(row, value_method) ⇒ Object
Instance Method Details
#check_boxes_input(method, options = {}) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/jquery_ui_form/inputs/check_boxes_input.rb', line 5 def check_boxes_input(method, = {}) # radio_button(method, tag_value, options) legend, = label_text(method, ) current_values = .delete(:values) || current_values_from_association(method) collection = .delete(:collection) || collection_from_association(method) = .delete(:html_label) || {} [:class] = [:class].gsub('ui-check_boxes-input','ui-boolean-input') = .delete(:buttonset) || false = {} [:class] = "to-buttonset" if label_method = .delete(:label_method) || :name value_method = .delete(:value_method) || :id output = fieldset(legend.html_safe, ) do template.concat(inline_hint(.delete(:hint))) template.concat(inline_error(method)) collection.each do |row| label_text = label_from_association(row,label_method) value_text = value_from_association(row,value_method) checked = current_values.include?(value_text.to_s) if template.concat(template.check_box_tag("#{@object_name}[#{method}][]", value_text, checked, .merge(:id => name_to_id("#{@object_name}_#{method}_#{value_text}")))) template.concat(label(name_to_id("#{method}_#{value_text}"), label_text, )) else template.concat(column do template.concat(label(name_to_id("#{method}_#{value_text}"), label_text, )) template.concat(template.check_box_tag("#{@object_name}[#{method}][]", value_text, checked, .merge(:id => name_to_id("#{@object_name}_#{method}_#{value_text}")))) end) end end end end |
#collection_from_association(method) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/jquery_ui_form/inputs/check_boxes_input.rb', line 69 def collection_from_association(method) return [] unless @object || @object.respond_to?(method) return [] unless @object.send(method).is_a?(Array) if target = @object.send(method).first target.class.all else begin collection = method.to_s.classify.constantize collection.all rescue return [] end end end |
#current_values_from_association(method) ⇒ Object
63 64 65 66 67 |
# File 'lib/jquery_ui_form/inputs/check_boxes_input.rb', line 63 def current_values_from_association(method) return [] unless @object || @object.respond_to?(method) return [] unless @object.send(method).is_a?(Array) @object.send(method).map{|row| row.id.to_s} end |
#label_from_association(row, label_method) ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/jquery_ui_form/inputs/check_boxes_input.rb', line 42 def label_from_association(row, label_method) return row[0] if row.is_a?(Array) return row if row.is_a?(String) if row.respond_to?(label_method) row.send(label_method) else row end end |
#value_from_association(row, value_method) ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/jquery_ui_form/inputs/check_boxes_input.rb', line 53 def value_from_association(row, value_method) return row[1] if row.is_a?(Array) return row if row.is_a?(String) if row.respond_to?(value_method) row.send(value_method) else row end end |