Class: Motr::Forms::Builder
- Inherits:
-
Base
- Object
- ActionView::Helpers::FormBuilder
- Base
- Motr::Forms::Builder
- Defined in:
- lib/motr/forms/builder.rb
Overview
Default Motr form builder. Extends the passed input tags to include additional html attributes, primarily for javascript integration.
Instance Attribute Summary
Attributes inherited from Base
#current_field_type, #field_order, #template
Instance Method Summary (collapse)
-
- (Object) button(value = nil, options = {})
Creates a button tag to be used in a form instead of the default input to help make CSS styling easier.
-
- (Object) label(method, text = nil, options = {}, &block)
Modified label tag to support adding a 'required' asterisk to the end of the label.
-
- (Array) options_for_state_select(abbreviate = false, incl_international = false)
protected
Returns a list of US states as an array.
-
- (String) state_select(method, options = {}, html_options = {})
Generate a select tag with the 50 US states as options.
Methods inherited from Base
#attribute_required?, #content_tag, #errors_on_attribute?, #fields_for, #options_require_validation?, #render_field_as_custom, #render_field_with_errors, #required_by_option?, #validates_inclusion?, #validates_presence?, #validates_uniqueness?, #validators_for, #validators_for?
Instance Method Details
- (Object) button(value = nil, options = {})
Creates a button tag to be used in a form instead of the default input to help make CSS styling easier
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/motr/forms/builder.rb', line 51 def (value = nil, = {}) value, = nil, value if value.is_a?(Hash) value ||= submit_default_value value = [image_tag(icon, :class => 'icon'), value].join(' ') if icon = .delete(:icon) klasses = (.delete(:class) || "").split(" ") klasses << "button" ['class'] = klasses.join(" ") content_tag(:button, value.to_s.html_safe, .reverse_merge!({ "type" => "submit", "name" => "commit" })) end |
- (Object) label(method, text = nil, options = {}, &block)
Modified label tag to support adding a 'required' asterisk to the end of the label. Same params as the original implementation
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/motr/forms/builder.rb', line 27 def label(method, text = nil, = {}, &block) #:nodoc: , text = text, nil if text.is_a?(Hash) text ||= method.to_s.humanize .stringify_keys! klasses = (.delete(['class']) || "").split(" ") klasses << Motr::Forms.error_class if errors_on_attribute?(method) ['class'] = klasses.join(" ") unless klasses.compact.empty? text = "#{text} <abbr title='Required'>*</abbr>".html_safe if attribute_required?(method) || required_by_option?(.delete('required')) super(method, text, , &block) end |
- (Array) options_for_state_select(abbreviate = false, incl_international = false) (protected)
Returns a list of US states as an array
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/motr/forms/builder.rb', line 93 def (abbreviate = false, incl_international = false) incl_international ||= false state_list = [ ['Alabama', "AL"],['Alaska', "AK"],['Arizona', "AZ"],['Arkansas', "AR"],['California', "CA"],['Colorado', "CO"], ['Connecticut', "CT"],['District of Columbia', "DC"],['Delaware', "DE"],['Florida', "FL"],['Georgia', "GA"], ['Hawaii', "HI"],['Idaho', "ID"],['Illinois', "IL"],['Indiana', "IN"],['Iowa', "IA"],['Kansas', "KS"],['Kentucky', "KY"], ['Louisiana', "LA"],['Maine', "ME"],['Maryland', "MD"],['Massachusetts', "MA"],['Michigan', "MI"],['Minnesota', "MN"], ['Mississippi', "MS"],['Missouri', "MO"],['Montana', "MT"],['Nebraska', "NE"],['Nevada', "NV"],['New Hampshire', "NH"], ['New Jersey', "NJ"],['New Mexico', "NM"],['New York', "NY"],['North Carolina', "NC"],['North Dakota', "ND"], ['Ohio', "OH"],['Oklahoma', "OK"],['Oregon', "OR"],['Pennsylvania', "PA"],['Rhode Island', "RI"],['South Carolina', "SC"], ['South Dakota', "SD"],['Tennessee', "TN"],['Texas', "TX"],['Utah', "UT"],['Vermont', "VT"],['Virginia', "VA"],['Washington', "WA"], ['West Virginia', "WV"],['Wisconsin', "WI"],['Wyoming', "WY"] ].map do |state| (abbreviate ? state : [state.first, state.first]) end state_list << ['International', incl_international] unless incl_international === false state_list end |
- (String) state_select(method, options = {}, html_options = {})
Generate a select tag with the 50 US states as options
76 77 78 79 80 |
# File 'lib/motr/forms/builder.rb', line 76 def state_select(method, = {}, = {}) abbr = .delete(:abbreviate) abbr = !(abbr.nil? || abbr === false) select(method, @template.((abbr, .delete(:international)), @object.try(:state)), , ) end |