Class: AppFormBuilder
- Inherits:
-
ActionView::Helpers::FormBuilder
- Object
- ActionView::Helpers::FormBuilder
- AppFormBuilder
- Defined in:
- lib/AppFormBuilder.rb
Instance Method Summary collapse
- #boolean_filter(field, options = {}) ⇒ Object
- #checkbox_set(field, values, options = {}) ⇒ Object
- #format_attrs(attrs) ⇒ Object
- #getError(field) ⇒ Object
- #label(field, text) ⇒ Object
- #label_options(field) ⇒ Object
- #language_select(field, options = {}) ⇒ Object
- #submit(text, options = {}) ⇒ Object
Instance Method Details
#boolean_filter(field, options = {}) ⇒ Object
79 80 81 |
# File 'lib/AppFormBuilder.rb', line 79 def boolean_filter(field, = {}) collection_select field, [['Ja/Nej', ''], ['Ja', 'true'], ['Nej', 'false']], :last, :first, end |
#checkbox_set(field, values, options = {}) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/AppFormBuilder.rb', line 52 def checkbox_set(field, values, = {}) current = object.send(field) ix = 0; values.map do |value| attrs = { :type => 'checkbox', :name => "#{@object_name}[#{field}][]", :id => "#{@object_name}_#{field}_#{ix += 1}", :value => value } attrs[:checked] = 'checked' if current.nil? || current.include?(value) %Q{ <div class="checkbox field"> <input #{format_attrs attrs} /> <label for="#{@object_name}_#{field}_#{ix}">#{value}</label> </div> } end.join("\n") end |
#format_attrs(attrs) ⇒ Object
73 74 75 76 77 |
# File 'lib/AppFormBuilder.rb', line 73 def format_attrs(attrs) attrs.map do |key, value| "#{key}=\"#{value}\"" end.join " " end |
#getError(field) ⇒ Object
47 48 49 50 |
# File 'lib/AppFormBuilder.rb', line 47 def getError(field) return nil if object.nil? || !object.respond_to?(:errors) object.errors[field] end |
#label(field, text) ⇒ Object
39 40 41 |
# File 'lib/AppFormBuilder.rb', line 39 def label(field, text) super(field, text, (field)) end |
#label_options(field) ⇒ Object
43 44 45 |
# File 'lib/AppFormBuilder.rb', line 43 def (field) getError(field) ? { :class => 'error' } : {} end |
#language_select(field, options = {}) ⇒ Object
83 84 85 |
# File 'lib/AppFormBuilder.rb', line 83 def language_select(field, = {}) collection_select field, ['sv', 'en'], :to_s, :to_s, end |
#submit(text, options = {}) ⇒ Object
33 34 35 36 37 |
# File 'lib/AppFormBuilder.rb', line 33 def submit(text, = {}) @template.content_tag('button', text, .merge(:type => 'submit') ) end |