Module: Lipstick::Helpers::FormHelper
- Includes:
- ActionView::Helpers::FormTagHelper
- Defined in:
- lib/lipstick/helpers/form_helper.rb
Instance Method Summary collapse
- #button_tag(content_or_options = nil, options = nil, &block) ⇒ Object
- #check_box_tag ⇒ Object
- #date_field_tag(name, value = nil, **opts) ⇒ Object
- #delete_button_tag(url, text: true, **opts) ⇒ Object
- #field_block(html_opts = {}) ⇒ Object
- #form_for(obj, opts = {}, &block) ⇒ Object
- #grouped_search_field(filter, placeholder) ⇒ Object
- #hidden_fields(&block) ⇒ Object
- #inline_form_tag(url_for_options = {}, options = {}) ⇒ Object
- #orig_text_field_tag ⇒ Object
- #radio_button_tag(name, value, checked = false, options = {}) ⇒ Object
- #search_button ⇒ Object
- #search_filter_text_field(filter, placeholder) ⇒ Object
- #search_form_input_tag(filter, placeholder) ⇒ Object
- #search_form_tag(filter, url: nil, placeholder: 'Search within these entries') ⇒ Object
- #select_tag(name, option_tags = nil, **opts) ⇒ Object
- #text_area_tag(name, content = nil, opts = {}) ⇒ Object
- #text_field_tag(name, value = nil, opts = {}) ⇒ Object
-
#validate_form(selector, sym = nil) ⇒ Object
Generates the wrapping code for validating a form.
Instance Method Details
#button_tag(content_or_options = nil, options = nil, &block) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/lipstick/helpers/form_helper.rb', line 100 def ( = nil, = nil, &block) if .is_a?(Hash) [:class] ||= 'btn-default' add_css_class(, 'btn') super else ||= {} [:class] ||= 'btn-default' add_css_class(, 'btn') super(, , &block) end end |
#check_box_tag ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/lipstick/helpers/form_helper.rb', line 22 def check_box_tag(*) content_tag('div', class: 'checkbox') do content_tag('label') do concat(super) concat(capture { yield }) end end end |
#date_field_tag(name, value = nil, **opts) ⇒ Object
90 91 92 93 |
# File 'lib/lipstick/helpers/form_helper.rb', line 90 def date_field_tag(name, value = nil, **opts) opts[:class] = "#{opts[:class]} date-picker".strip text_field_tag(name, value, opts) end |
#delete_button_tag(url, text: true, **opts) ⇒ Object
113 114 115 116 117 118 119 120 |
# File 'lib/lipstick/helpers/form_helper.rb', line 113 def (url, text: true, **opts) action = text&.is_a?(String) ? text : 'Delete' content_tag('div', class: 'btn-group') do concat(delete_dropdown_opener(text && action, opts)) concat(confirm_delete_dropdown(url, action)) end end |
#field_block(html_opts = {}) ⇒ Object
8 9 10 11 |
# File 'lib/lipstick/helpers/form_helper.rb', line 8 def field_block(html_opts = {}) add_css_class(html_opts, 'form-group') content_tag('div', html_opts) { yield } end |
#form_for(obj, opts = {}, &block) ⇒ Object
122 123 124 125 |
# File 'lib/lipstick/helpers/form_helper.rb', line 122 def form_for(obj, opts = {}, &block) opts[:builder] = BootstrapFormBuilder super(obj, opts, &block) end |
#grouped_search_field(filter, placeholder) ⇒ Object
67 68 69 70 71 72 |
# File 'lib/lipstick/helpers/form_helper.rb', line 67 def grouped_search_field(filter, placeholder) content_tag('div', class: 'input-group') do concat(search_filter_text_field(filter, placeholder)) concat(content_tag('span', , class: 'input-group-btn')) end end |
#hidden_fields(&block) ⇒ Object
74 75 76 |
# File 'lib/lipstick/helpers/form_helper.rb', line 74 def hidden_fields(&block) content_tag('div', style: 'display: none;', &block) end |
#inline_form_tag(url_for_options = {}, options = {}) ⇒ Object
33 34 35 36 |
# File 'lib/lipstick/helpers/form_helper.rb', line 33 def inline_form_tag( = {}, = {}) add_css_class(, 'form-inline') form_tag(, ) { yield } end |
#orig_text_field_tag ⇒ Object
78 |
# File 'lib/lipstick/helpers/form_helper.rb', line 78 alias orig_text_field_tag text_field_tag |
#radio_button_tag(name, value, checked = false, options = {}) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/lipstick/helpers/form_helper.rb', line 13 def (name, value, checked = false, = {}) content_tag('div', class: 'radio') do content_tag('label') do concat(super) concat(capture { yield }) end end end |
#search_button ⇒ Object
60 61 62 63 64 65 |
# File 'lib/lipstick/helpers/form_helper.rb', line 60 def (type: 'submit') do concat(icon_tag('search')) concat(' Search') end end |
#search_filter_text_field(filter, placeholder) ⇒ Object
53 54 55 56 57 58 |
# File 'lib/lipstick/helpers/form_helper.rb', line 53 def search_filter_text_field(filter, placeholder) orig_text_field_tag(:filter, filter, placeholder: placeholder, autocomplete: 'off', class: 'form-control') end |
#search_form_input_tag(filter, placeholder) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/lipstick/helpers/form_helper.rb', line 45 def search_form_input_tag(filter, placeholder) content_tag('div', class: 'row') do content_tag('div', grouped_search_field( filter, placeholder ), class: 'col-lg-12') end end |
#search_form_tag(filter, url: nil, placeholder: 'Search within these entries') ⇒ Object
38 39 40 41 42 43 |
# File 'lib/lipstick/helpers/form_helper.rb', line 38 def search_form_tag(filter, url: nil, placeholder: 'Search within these entries') form_tag(url, method: :get) do field_block { search_form_input_tag(filter, placeholder) } end end |
#select_tag(name, option_tags = nil, **opts) ⇒ Object
95 96 97 98 |
# File 'lib/lipstick/helpers/form_helper.rb', line 95 def select_tag(name, = nil, **opts) add_css_class(opts, 'form-control') super end |
#text_area_tag(name, content = nil, opts = {}) ⇒ Object
85 86 87 88 |
# File 'lib/lipstick/helpers/form_helper.rb', line 85 def text_area_tag(name, content = nil, opts = {}) add_css_class(opts, 'form-control') super end |
#text_field_tag(name, value = nil, opts = {}) ⇒ Object
80 81 82 83 |
# File 'lib/lipstick/helpers/form_helper.rb', line 80 def text_field_tag(name, value = nil, opts = {}) add_css_class(opts, 'form-control') super end |
#validate_form(selector, sym = nil) ⇒ Object
Generates the wrapping code for validating a form. The selector is passed to jQuery, and must uniquely select the form being validated. ‘sym` is the object name when using a `form_for` helper to generate the form.
e.g. <%=
validate_form('#new-test-object', :test_object) do |v|
v.validate_field(:name, ...) # Validate the test_object[name] field
end
%>
138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/lipstick/helpers/form_helper.rb', line 138 def validate_form(selector, sym = nil) opts = { type: 'application/vnd.aaf.lipstick.validations+json', 'data-target': selector, class: 'lipstick-validations' } content_tag('script', opts) do validation_json(sym) { |v| yield v }.html_safe end end |