Class: Frontpack::FormBuilder
- Inherits:
-
ActionView::Helpers::FormBuilder
- Object
- ActionView::Helpers::FormBuilder
- Frontpack::FormBuilder
- Includes:
- ActionView::Helpers::UrlHelper
- Defined in:
- app/helpers/frontpack/form_builder.rb
Overview
Custom input builders
Instance Method Summary collapse
- #autocomplete_field(method, options = {}) ⇒ Object
- #date_field(method, options = {}, _html_options = {}) ⇒ Object
- #email_field(method, options = {}) ⇒ Object
- #enum_field(method, options = {}) ⇒ Object
- #label(method, text = nil, options = {}) ⇒ Object
- #number_field(method, options = {}) ⇒ Object
- #password_field(method, options = {}) ⇒ Object
- #select(method, choices = nil, options = {}, html_options = {}) ⇒ Object
- #switch_field(method, options = {}) ⇒ Object
- #text_area(method, options = {}) ⇒ Object
- #text_field(method, options = {}) ⇒ Object
Methods included from ActionView::Helpers::UrlHelper
Instance Method Details
#autocomplete_field(method, options = {}) ⇒ Object
23 24 25 26 27 28 |
# File 'app/helpers/frontpack/form_builder.rb', line 23 def autocomplete_field(method, = {}) relation = @object.class.reflect_on_association(method) uri = relation.class_name.underscore.sub('::', '/') display_field = relation.klass.autocomplete_display_fields[1] text_field(relation.foreign_key, .merge('data-url': "/autocomplete/#{uri}", is: 'auto-complete', 'display-value': @object.send(method)&.send(display_field))) end |
#date_field(method, options = {}, _html_options = {}) ⇒ Object
66 67 68 |
# File 'app/helpers/frontpack/form_builder.rb', line 66 def date_field(method, = {}, = {}) @template.text_field(@object_name, method, (.merge(type: :date))) end |
#email_field(method, options = {}) ⇒ Object
40 41 42 43 |
# File 'app/helpers/frontpack/form_builder.rb', line 40 def email_field(method, = {}) (method, ) if @object super end |
#enum_field(method, options = {}) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'app/helpers/frontpack/form_builder.rb', line 9 def enum_field(method, = {}) excluded_keys = .key?(:except) ? [:except] : [] if @object opts = { selected: @object.send(method) } select method, @object.(method, excluded_keys), opts, elsif .key?(:model) model = [:model] select method, model.(method, excluded_keys), .slice(:selected, :include_blank, :prompt), else select method, [], opts, end end |
#label(method, text = nil, options = {}) ⇒ Object
50 51 52 53 |
# File 'app/helpers/frontpack/form_builder.rb', line 50 def label(method, text = nil, = {}, &) method, if @object super(method, text, , &) end |
#number_field(method, options = {}) ⇒ Object
60 61 62 63 64 |
# File 'app/helpers/frontpack/form_builder.rb', line 60 def number_field(method, = {}) (method, ) if @object super(method, ) end |
#password_field(method, options = {}) ⇒ Object
35 36 37 38 |
# File 'app/helpers/frontpack/form_builder.rb', line 35 def password_field(method, = {}) (method, ) if @object super end |
#select(method, choices = nil, options = {}, html_options = {}) ⇒ Object
55 56 57 58 |
# File 'app/helpers/frontpack/form_builder.rb', line 55 def select(method, choices = nil, = {}, = {}, &) (method, , css_class: Frontpack::FormBuilderOptions.select_class) if @object super end |
#switch_field(method, options = {}) ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'app/helpers/frontpack/form_builder.rb', line 70 def switch_field(method, = {}) @template.content_tag(:div, class: 'switch-toggle') do toggle_box = check_box(method, { checked: @object.send(method) }.merge()) opts = .merge(for: "#{@object_name}_#{method}") opts[:style] = "--on-icon: '#{[:'data-on-icon']}';" if .key? :'data-on-icon' opts[:style] += "--off-icon: '#{[:'data-off-icon']}';" if .key? :'data-off-icon' toggle_box + @template.content_tag(:label, nil, opts) end end |
#text_area(method, options = {}) ⇒ Object
45 46 47 48 |
# File 'app/helpers/frontpack/form_builder.rb', line 45 def text_area(method, = {}) (method, ) if @object super end |
#text_field(method, options = {}) ⇒ Object
30 31 32 33 |
# File 'app/helpers/frontpack/form_builder.rb', line 30 def text_field(method, = {}) (method, ) if @object super(method, ) end |