Class: 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
-
#button(value = nil, options = {}) ⇒ Object
Creates a button tag to be used in a form instead of the default input to help make CSS styling easier.
-
#label(method, text = nil, options = {}, &block) ⇒ Object
Modified label tag to support adding a ‘required’ asterisk to the end of the label.
-
#state_select(method, options = {}, html_options = {}) ⇒ String
Generate a select tag with the 50 US states as options.
Methods inherited from Base
Instance Method Details
#button(value = nil, options = {}) ⇒ Object
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 |
#label(method, text = nil, options = {}, &block) ⇒ Object
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 |
#state_select(method, options = {}, html_options = {}) ⇒ String
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 |