Module: BootstrapConcerns::FormBuilder
- Defined in:
- lib/bootstrap_concerns/form_builder.rb
Constant Summary collapse
- FORM_LABEL_BASE_CLASS =
"form-label".freeze
- FORM_CHECK_INPUT_BASE_CLASS =
"form-check-input".freeze
- FORM_CONTROL_BASE_CLASS =
"form-control".freeze
- FORM_CONTROL_PLAIN_TEXT_BASE_CLASS =
"form-control-plaintext".freeze
- FORM_SELECT_BASE_CLASS =
"form-select".freeze
- REQUIRED_CLASS =
"required".freeze
Instance Method Summary collapse
- #bs_button(value = nil, options = {}) ⇒ Object
- #bs_check_box(method, options = {}, checked_value = "1", unchecked_value = "0") ⇒ Object
- #bs_check_label(method, text = nil, options = {}) ⇒ Object
- #bs_collection_select(method, collection, value_method, text_method, options = {}, html_options = {}) ⇒ Object
- #bs_color_field(method, options = {}) ⇒ Object
- #bs_date_field(method, options = {}) ⇒ Object
- #bs_datetime_field(method, options = {}) ⇒ Object
- #bs_email_field(method, options = {}) ⇒ Object
- #bs_file_field(method, options = {}) ⇒ Object
- #bs_form_group(method, type, *args) ⇒ Object
- #bs_grouped_collection_select(method, collection, group_method, group_label_method, option_key_method, option_value_method, options = {}, html_options = {}) ⇒ Object
- #bs_label(method, text = nil, options = {}) ⇒ Object
- #bs_number_field(method, options = {}) ⇒ Object
- #bs_password_field(method, options = {}) ⇒ Object
- #bs_phone_field(method, options = {}) ⇒ Object
- #bs_radio_button(method, tag_value, options = {}) ⇒ Object
- #bs_readonly_plain_text_field(method, options = {}) ⇒ Object
- #bs_save_submit(options = {}) ⇒ Object
- #bs_search_field(method, options = {}) ⇒ Object
- #bs_select(method, choices = nil, options = {}, html_options = {}) ⇒ Object
- #bs_submit(value = nil, options = {}) ⇒ Object
- #bs_text_area(method, options = {}) ⇒ Object
- #bs_text_field(method, options = {}) ⇒ Object
- #bs_url_field(method, options = {}) ⇒ Object
Instance Method Details
#bs_button(value = nil, options = {}) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/bootstrap_concerns/form_builder.rb', line 12 def (value = nil, = {}, &) = value.is_a?(Hash) ? value : .deep_merge!(Option.()) (value, , &) end |
#bs_check_box(method, options = {}, checked_value = "1", unchecked_value = "0") ⇒ Object
19 20 21 |
# File 'lib/bootstrap_concerns/form_builder.rb', line 19 def bs_check_box(method, = {}, checked_value = "1", unchecked_value = "0") check_box(method, (), checked_value, unchecked_value) end |
#bs_check_label(method, text = nil, options = {}) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/bootstrap_concerns/form_builder.rb', line 23 def bs_check_label(method, text = nil, = {}, &) = text.is_a?(Hash) ? text : .deep_merge!(()) label(method, text, , &) end |
#bs_collection_select(method, collection, value_method, text_method, options = {}, html_options = {}) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/bootstrap_concerns/form_builder.rb', line 34 def bs_collection_select(method, collection, value_method, text_method, = {}, = {}) collection_select( method, collection, value_method, text_method, , (, ) ) end |
#bs_color_field(method, options = {}) ⇒ Object
30 31 32 |
# File 'lib/bootstrap_concerns/form_builder.rb', line 30 def bs_color_field(method, = {}) color_field(method, ()) end |
#bs_date_field(method, options = {}) ⇒ Object
45 46 47 |
# File 'lib/bootstrap_concerns/form_builder.rb', line 45 def bs_date_field(method, = {}) date_field(method, ()) end |
#bs_datetime_field(method, options = {}) ⇒ Object
49 50 51 |
# File 'lib/bootstrap_concerns/form_builder.rb', line 49 def bs_datetime_field(method, = {}) datetime_field(method, ()) end |
#bs_email_field(method, options = {}) ⇒ Object
53 54 55 |
# File 'lib/bootstrap_concerns/form_builder.rb', line 53 def bs_email_field(method, = {}) email_field(method, ()) end |
#bs_file_field(method, options = {}) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/bootstrap_concerns/form_builder.rb', line 105 def bs_file_field(method, = {}) file_field( method, { class: FORM_CONTROL_BASE_CLASS, direct_upload: true, data: { controller: "direct-upload-field", action: " direct-upload:initialize->direct-upload-field#setup\n direct-upload:progress->direct-upload-field#progress\n direct-upload:error->direct-upload-field#error\n direct-upload:end->direct-upload-field#end\n ACTION\n }\n }.deep_merge(options)\n )\nend\n".squish |
#bs_form_group(method, type, *args) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/bootstrap_concerns/form_builder.rb', line 57 def bs_form_group(method, type, *args) = args.find { it.is_a?(Hash) && it.key?(:required) }.to_h input_group = args.find { it.is_a?(Hash) && it[:input_group] } || {} input_group_flag = input_group[:input_group].present? content_tag(:div, class: ComponentsHelper::MARGIN) do concat bs_label(method, .slice(:required)) if input_group_flag concat(content_tag(:div, class: "input-group") do public_send("bs_#{type}", method, *args) end) concat (method, outside: true) else concat(public_send("bs_#{type}", method, *args)) concat (method) end end end |
#bs_grouped_collection_select(method, collection, group_method, group_label_method, option_key_method, option_value_method, options = {}, html_options = {}) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/bootstrap_concerns/form_builder.rb', line 76 def bs_grouped_collection_select( method, collection, group_method, group_label_method, option_key_method, option_value_method, = {}, = {} ) grouped_collection_select( method, collection, group_method, group_label_method, option_key_method, option_value_method, , (, ) ) end |
#bs_label(method, text = nil, options = {}) ⇒ Object
98 99 100 101 102 103 |
# File 'lib/bootstrap_concerns/form_builder.rb', line 98 def bs_label(method, text = nil, = {}, &) = text.is_a?(Hash) ? text : .deep_merge!(()) label(method, text, , &) end |
#bs_number_field(method, options = {}) ⇒ Object
124 125 126 |
# File 'lib/bootstrap_concerns/form_builder.rb', line 124 def bs_number_field(method, = {}) number_field(method, ()) end |
#bs_password_field(method, options = {}) ⇒ Object
128 129 130 |
# File 'lib/bootstrap_concerns/form_builder.rb', line 128 def bs_password_field(method, = {}) password_field(method, ()) end |
#bs_phone_field(method, options = {}) ⇒ Object
155 156 157 |
# File 'lib/bootstrap_concerns/form_builder.rb', line 155 def bs_phone_field(method, = {}) phone_field(method, ()) end |
#bs_radio_button(method, tag_value, options = {}) ⇒ Object
132 133 134 |
# File 'lib/bootstrap_concerns/form_builder.rb', line 132 def (method, tag_value, = {}) (method, tag_value, ()) end |
#bs_readonly_plain_text_field(method, options = {}) ⇒ Object
159 160 161 162 163 164 |
# File 'lib/bootstrap_concerns/form_builder.rb', line 159 def bs_readonly_plain_text_field(method, = {}) text_field( method, Option.(, FORM_CONTROL_PLAIN_TEXT_BASE_CLASS).deep_merge(readonly: true) ) end |
#bs_save_submit(options = {}) ⇒ Object
140 141 142 |
# File 'lib/bootstrap_concerns/form_builder.rb', line 140 def bs_save_submit( = {}) bs_submit("Save", ) end |
#bs_search_field(method, options = {}) ⇒ Object
136 137 138 |
# File 'lib/bootstrap_concerns/form_builder.rb', line 136 def bs_search_field(method, = {}) search_field(method, ()) end |
#bs_select(method, choices = nil, options = {}, html_options = {}) ⇒ Object
144 145 146 |
# File 'lib/bootstrap_concerns/form_builder.rb', line 144 def bs_select(method, choices = nil, = {}, = {}, &) select(method, choices, , (, ), &) end |
#bs_submit(value = nil, options = {}) ⇒ Object
148 149 150 151 152 153 |
# File 'lib/bootstrap_concerns/form_builder.rb', line 148 def bs_submit(value = nil, = {}) = value.is_a?(Hash) ? value : .deep_merge!(Option.()) submit(value, ) end |
#bs_text_area(method, options = {}) ⇒ Object
170 171 172 |
# File 'lib/bootstrap_concerns/form_builder.rb', line 170 def bs_text_area(method, = {}) text_area(method, ()) end |
#bs_text_field(method, options = {}) ⇒ Object
166 167 168 |
# File 'lib/bootstrap_concerns/form_builder.rb', line 166 def bs_text_field(method, = {}) text_field(method, ()) end |
#bs_url_field(method, options = {}) ⇒ Object
174 175 176 |
# File 'lib/bootstrap_concerns/form_builder.rb', line 174 def bs_url_field(method, = {}) url_field(method, ()) end |