Module: Homeschool::FormBuildr::InstanceMethods

Defined in:
lib/form_buildr.rb

Instance Method Summary collapse

Instance Method Details

#label_for(method, options = {}) ⇒ Object



41
42
43
44
45
46
47
48
49
# File 'lib/form_buildr.rb', line 41

def label_for(method, options={})
  options = {:label => options} if options.is_a? String
  begin
    label = options[:label] || @object_name.to_s.classify.constantize.human_name(method)
  rescue NameError
    label = method.to_s.titleize
  end
  %{<label class="fieldLabel" for="#{options[:id] || "#{@object_name}_#{method}"}">#{label}#{":" if !options[:no_colon]}</label>}
end

#labeled_check_box(method, options = {}, checked_value = "1", unchecked_value = "0") ⇒ Object



56
57
58
# File 'lib/form_buildr.rb', line 56

def labeled_check_box(method, options={}, checked_value="1", unchecked_value="0")
  send(:check_box, method, options.without(:label, :no_colon), checked_value, unchecked_value) + send(:label_for, method, options.update(:no_colon => true))
end

#labeled_collection_select(method, collection, value_method, text_method, options = {}, html_options = {}) ⇒ Object



64
65
66
# File 'lib/form_buildr.rb', line 64

def labeled_collection_select(method, collection, value_method, text_method, options={}, html_options={})
  label_for(method, options) + collection_select(method, collection, value_method, text_method, options.without(:label, :no_colon), html_options)
end

#labeled_radio_button(method, tag_value, options = {}) ⇒ Object



51
52
53
54
# File 'lib/form_buildr.rb', line 51

def labeled_radio_button(method, tag_value, options={})
  id = %{#{@object_name}_#{method}_#{tag_value}}
  send(:radio_button, method, tag_value, {:id => id}.update(options.without(:label, :no_colon))) + send(:label_for, method, {:no_colon => true, :label => tag_value.to_s.humanize, :id => id}.update(options))
end

#labeled_select(method, choices, options = {}, html_options = {}) ⇒ Object



60
61
62
# File 'lib/form_buildr.rb', line 60

def labeled_select(method, choices, options={}, html_options={})
  label_for(method, options) + select(method, choices, options.without(:label, :no_colon), html_options)
end