Module: PagesCore::LabelledFormBuilder
- Included in:
- FormBuilder
- Defined in:
- app/helpers/pages_core/labelled_form_builder.rb
Instance Method Summary collapse
- #field_with_label(attr, str, label = nil, class_name = nil) ⇒ Object
- #label_and_errors(attribute, label_text) ⇒ Object
- #label_for(attribute, label_text = nil) ⇒ Object
- #labelled_check_box(attr, label = nil, options = {}, checked = "1", unchecked = "0") ⇒ Object
- #labelled_country_select(attr, label = nil, priority = {}, opts = {}, html_opts = {}) ⇒ Object
- #labelled_date_select(attribute, label_text = nil, options = {}) ⇒ Object
- #labelled_datetime_select(attribute, label_text = nil, options = {}) ⇒ Object
- #labelled_file_field(attribute, label_text = nil, options = {}) ⇒ Object
- #labelled_image_file_field(attribute, label_text = nil, options = {}) ⇒ Object
- #labelled_password_field(attribute, label_text = nil, options = {}) ⇒ Object
- #labelled_select(attribute, choices, label_text = nil, options = {}) ⇒ Object
- #labelled_text_area(attribute, label_text = nil, options = {}) ⇒ Object
- #labelled_text_field(attribute, label_text = nil, options = {}) ⇒ Object
- #labelled_time_select(attribute, label_text = nil, options = {}) ⇒ Object
Instance Method Details
#field_with_label(attr, str, label = nil, class_name = nil) ⇒ Object
5 6 7 8 9 |
# File 'app/helpers/pages_core/labelled_form_builder.rb', line 5 def field_with_label(attr, str, label = nil, class_name = nil) classes = ["field", class_name] classes << "field-with-errors" if object.errors[attr].any? tag.div(label_for(attr, label) + str, class: classes.compact.join(" ")) end |
#label_and_errors(attribute, label_text) ⇒ Object
11 12 13 14 15 16 |
# File 'app/helpers/pages_core/labelled_form_builder.rb', line 11 def label_and_errors(attribute, label_text) return label_text unless object.errors[attribute].any? error = tag.span(object.errors[attribute].first, class: "error") safe_join([label_text, error], " ") end |
#label_for(attribute, label_text = nil) ⇒ Object
18 19 20 21 22 |
# File 'app/helpers/pages_core/labelled_form_builder.rb', line 18 def label_for(attribute, label_text = nil) label_text ||= object.class.human_attribute_name(attribute) tag.label(label_and_errors(attribute, label_text), for: [object.class.to_s.underscore, attribute].join("_")) end |
#labelled_check_box(attr, label = nil, options = {}, checked = "1", unchecked = "0") ⇒ Object
24 25 26 27 28 29 30 |
# File 'app/helpers/pages_core/labelled_form_builder.rb', line 24 def labelled_check_box( attr, label = nil, = {}, checked = "1", unchecked = "0" ) labelled_field(attr, label, ) do |opts| check_box(attr, opts, checked, unchecked) end end |
#labelled_country_select(attr, label = nil, priority = {}, opts = {}, html_opts = {}) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/helpers/pages_core/labelled_form_builder.rb', line 32 def labelled_country_select( attr, label = nil, priority = {}, opts = {}, html_opts = {} ) if priority.is_a?(Hash) return labelled_field(attr, label, priority) do || country_select(attr, , opts, html_opts) end end labelled_field(attr, label, opts) do || country_select(attr, priority, , html_opts) end end |
#labelled_date_select(attribute, label_text = nil, options = {}) ⇒ Object
45 46 47 48 49 |
# File 'app/helpers/pages_core/labelled_form_builder.rb', line 45 def labelled_date_select(attribute, label_text = nil, = {}) labelled_field(attribute, label_text, ) do |opts| date_select(attribute, opts) end end |
#labelled_datetime_select(attribute, label_text = nil, options = {}) ⇒ Object
51 52 53 54 55 |
# File 'app/helpers/pages_core/labelled_form_builder.rb', line 51 def labelled_datetime_select(attribute, label_text = nil, = {}) labelled_field(attribute, label_text, ) do |opts| datetime_select(attribute, opts) end end |
#labelled_file_field(attribute, label_text = nil, options = {}) ⇒ Object
57 58 59 60 61 |
# File 'app/helpers/pages_core/labelled_form_builder.rb', line 57 def labelled_file_field(attribute, label_text = nil, = {}) labelled_field(attribute, label_text, ) do |opts| file_field(attribute, opts) end end |
#labelled_image_file_field(attribute, label_text = nil, options = {}) ⇒ Object
63 64 65 66 67 |
# File 'app/helpers/pages_core/labelled_form_builder.rb', line 63 def labelled_image_file_field(attribute, label_text = nil, = {}) labelled_field(attribute, label_text, ) do |opts| image_file_field(attribute, opts) end end |
#labelled_password_field(attribute, label_text = nil, options = {}) ⇒ Object
69 70 71 72 73 |
# File 'app/helpers/pages_core/labelled_form_builder.rb', line 69 def labelled_password_field(attribute, label_text = nil, = {}) labelled_field(attribute, label_text, , "text-field") do |opts| password_field(attribute, opts) end end |
#labelled_select(attribute, choices, label_text = nil, options = {}) ⇒ Object
75 76 77 78 79 |
# File 'app/helpers/pages_core/labelled_form_builder.rb', line 75 def labelled_select(attribute, choices, label_text = nil, = {}) labelled_field(attribute, label_text, ) do |opts| select(attribute, choices, opts) end end |
#labelled_text_area(attribute, label_text = nil, options = {}) ⇒ Object
81 82 83 84 85 |
# File 'app/helpers/pages_core/labelled_form_builder.rb', line 81 def labelled_text_area(attribute, label_text = nil, = {}) labelled_field(attribute, label_text, , "text-area") do |opts| text_area(attribute, opts) end end |
#labelled_text_field(attribute, label_text = nil, options = {}) ⇒ Object
87 88 89 90 91 |
# File 'app/helpers/pages_core/labelled_form_builder.rb', line 87 def labelled_text_field(attribute, label_text = nil, = {}) labelled_field(attribute, label_text, , "text-field") do |opts| text_field(attribute, opts) end end |
#labelled_time_select(attribute, label_text = nil, options = {}) ⇒ Object
93 94 95 96 97 |
# File 'app/helpers/pages_core/labelled_form_builder.rb', line 93 def labelled_time_select(attribute, label_text = nil, = {}) labelled_field(attribute, label_text, ) do |opts| time_select(attribute, opts) end end |