Module: Tungsten::FormHelper
- Includes:
- ButtonHelper
- Defined in:
- app/helpers/tungsten/form_helper.rb
Constant Summary collapse
- INPUT_OPTIONS =
{ email: { type: "email", placeholder: "Email address", pattern: "[^@]+@[^@]+\\.[a-zA-Z]{2,}", autocorrect: "off", autocapitalize: "off", spellcheck: "false", data: { message: "Please enter a valid email address." } }, password: { type: "password", placeholder: "Password" }, text: { type: "text" }, number: { type: "number", step: "any" }, tel: { type: "tel", placeholder: "Phone number" }, url: { type: "text", placeholder: "Web address", autocorrect: "off", autocapitalize: "off", spellcheck: "false", pattern: ".+\\.[a-zA-Z]{2,}" }, card_number: { type: "text", required: true, pattern: "[0-9 -]{13,20}", placeholder: "Credit Card Number", data: { stripe: "number", message: "Please enter a valid credit card number." } }, card_month: { type: "text", required: true, pattern: "0[1-9]|1[012]", placeholder: "MM", data: { stripe: "exp_month", message: "Please enter a valid expiration month." } }, card_year: { type: "text", required: true, pattern: "[0-9]{4}", placeholder: "YYYY", data: { stripe: "exp_year", message: "Please enter a valid expiration year." } }, card_cvc: { type: "text", required: true, pattern: "[0-9]{3,4}", placeholder: "CVC", data: { stripe: "cvc", message: "Please enter a valid security code." } }, select_country: { type: "select", country_options: { include_blank: "Select a country", priority_countries: ["US", "GB", "CA"], }, html_options: {} } }
Instance Method Summary collapse
- #card_cvc_tag(name, value = nil, options = {}) ⇒ Object
- #card_month_tag(name, value = nil, options = {}) ⇒ Object
- #card_number_tag(name, value = nil, options = {}) ⇒ Object
- #card_year_tag(name, value = nil, options = {}) ⇒ Object
- #checkbox_input_tag(name, checked = false, options = {}) ⇒ Object
-
#email_input_tag(name, value = nil, options = {}) ⇒ Object
Email inputs.
- #number_input_tag(name, value = nil, options = {}) ⇒ Object
-
#password_input_tag(name, value = nil, options = {}) ⇒ Object
Passowrd inputs.
- #radio_button_input_tag(name, value, checked = false, options = {}) ⇒ Object
- #search_input_tag(name, value = nil, options = {}) ⇒ Object
-
#select_country_tag(name, options = {}, country_options = {}) ⇒ Object
Country select.
- #select_input_tag(name, option_tags = nil, options = {}, &block) ⇒ Object
- #slider_input_tag(name, options = {}) ⇒ Object
- #stacked_form_for(record, options = {}, &block) ⇒ Object
- #stacked_form_tag(form = nil) ⇒ Object
- #switch_input_tag(name, checked = false, options = {}) ⇒ Object
- #table_form_for(record, options = {}, &block) ⇒ Object
- #table_form_tag(form = nil) ⇒ Object
- #tel_input_tag(name, value = nil, options = {}) ⇒ Object
- #text_input_tag(name, value = nil, options = {}) ⇒ Object
- #textarea_tag(name, value = nil, options = {}, &block) ⇒ Object
- #url_input_tag(name, value = nil, options = {}) ⇒ Object
Methods included from ButtonHelper
#button, #button_classes, #copy_button, #destructive_button, #destructive_icon_button, #destructive_primary_button, #destructive_primary_icon_button, #icon_button, #primary_button, #primary_icon_button
Instance Method Details
#card_cvc_tag(name, value = nil, options = {}) ⇒ Object
184 185 186 |
# File 'app/helpers/tungsten/form_helper.rb', line 184 def card_cvc_tag(name, value=nil, ={}) input_tag(:card_cvc, name, value, ) end |
#card_month_tag(name, value = nil, options = {}) ⇒ Object
176 177 178 |
# File 'app/helpers/tungsten/form_helper.rb', line 176 def card_month_tag(name, value=nil, ={}) input_tag(:card_month, name, value, ) end |
#card_number_tag(name, value = nil, options = {}) ⇒ Object
172 173 174 |
# File 'app/helpers/tungsten/form_helper.rb', line 172 def card_number_tag(name, value=nil, ={}) input_tag(:card_number, name, value, ) end |
#card_year_tag(name, value = nil, options = {}) ⇒ Object
180 181 182 |
# File 'app/helpers/tungsten/form_helper.rb', line 180 def card_year_tag(name, value=nil, ={}) input_tag(:card_year, name, value, ) end |
#checkbox_input_tag(name, checked = false, options = {}) ⇒ Object
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'app/helpers/tungsten/form_helper.rb', line 209 def checkbox_input_tag(name, checked = false, = {}) value = true if checked.is_a? Hash = checked checked = false end [:type] = :checkbox tick_wrapper( name, ) do [:class] = 'input' concat tag :input, name: name, type: :hidden, value: false concat check_box_tag(name, value, checked, ) end end |
#email_input_tag(name, value = nil, options = {}) ⇒ Object
Email inputs
139 140 141 |
# File 'app/helpers/tungsten/form_helper.rb', line 139 def email_input_tag(name, value = nil, = {}) input_tag(:email, name, value, ) end |
#number_input_tag(name, value = nil, options = {}) ⇒ Object
164 165 166 |
# File 'app/helpers/tungsten/form_helper.rb', line 164 def number_input_tag(name, value = nil, = {}) input_tag(:number, name, value, ) end |
#password_input_tag(name, value = nil, options = {}) ⇒ Object
Passowrd inputs
144 145 146 |
# File 'app/helpers/tungsten/form_helper.rb', line 144 def password_input_tag(name, value = nil, = {}) input_tag(:password, name, value, ) end |
#radio_button_input_tag(name, value, checked = false, options = {}) ⇒ Object
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'app/helpers/tungsten/form_helper.rb', line 188 def (name, value, checked = false, = {}) if checked.is_a? Hash = checked checked = false end [:type] = :radio ([:class] ||= '') << ' input' [:data] ||= {} [:data][:show] = .delete(:show) tick_wrapper( name, ) do (name, value, checked, ) end end |
#search_input_tag(name, value = nil, options = {}) ⇒ Object
168 169 170 |
# File 'app/helpers/tungsten/form_helper.rb', line 168 def search_input_tag(name, value = nil, = {}) input_tag(:search, name, value, ) end |
#select_country_tag(name, options = {}, country_options = {}) ⇒ Object
Country select
126 127 128 129 130 131 132 133 134 135 136 |
# File 'app/helpers/tungsten/form_helper.rb', line 126 def select_country_tag(name, = {}, = {}) .reverse_merge! INPUT_OPTIONS[:select_country][:country_options] = INPUT_OPTIONS[:select_country][:html_options].deep_merge [:class] ||= ' ' [:class] += " #{label_class(:select)}" content_tag(:label, class: .delete(:class) ) do country_select :user, :country, , end end |
#select_input_tag(name, option_tags = nil, options = {}, &block) ⇒ Object
226 227 228 229 230 231 232 233 234 235 236 237 |
# File 'app/helpers/tungsten/form_helper.rb', line 226 def select_input_tag(name, =nil, ={}, &block) if .is_a? Hash = = nil end [:label] ||= .delete(:placeholder) ||= capture(&block).html_safe if block_given? input_tag(:select, name, .html_safe, ) end |
#slider_input_tag(name, options = {}) ⇒ Object
205 206 207 |
# File 'app/helpers/tungsten/form_helper.rb', line 205 def (name, ={}) input_tag(:range, name, ) end |
#stacked_form_for(record, options = {}, &block) ⇒ Object
112 113 114 115 116 |
# File 'app/helpers/tungsten/form_helper.rb', line 112 def stacked_form_for(record, = {}, &block) form_for record, do |f| stacked_form_tag f, &block end end |
#stacked_form_tag(form = nil) ⇒ Object
118 119 120 121 122 123 |
# File 'app/helpers/tungsten/form_helper.rb', line 118 def stacked_form_tag(form = nil) form.style = 'stacked' if form content_tag :div, class: 'stacked-form' do yield form if block_given? end end |
#switch_input_tag(name, checked = false, options = {}) ⇒ Object
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 |
# File 'app/helpers/tungsten/form_helper.rb', line 239 def switch_input_tag(name, checked = false, = {}) if checked.is_a? Hash = checked checked = false end if label_text = .delete(:label) label_text = content_tag(:span, class: 'label-text') { label_text } end if label_description = .delete(:description) label_description = content_tag(:span, class: 'label-description') { label_description } end content_tag(:label, class: "check-switch switch-label #{ 'check-switch-full-width' if [:full_width] }", data: { input: 'checkbox' }) do concat tag :input, name: name, type: :hidden, value: false concat label_text concat check_box_tag(name, true, checked, ) concat content_tag(:span, class: 'check-switch-panel') { concat content_tag(:span, class: 'check-switch-tick') { '' } } concat content_tag(:span, class: 'check-switch-label') { 'Enable' } concat label_description end end |
#table_form_for(record, options = {}, &block) ⇒ Object
99 100 101 102 103 |
# File 'app/helpers/tungsten/form_helper.rb', line 99 def table_form_for(record, = {}, &block) form_for record, do |f| table_form_tag f, &block end end |
#table_form_tag(form = nil) ⇒ Object
105 106 107 108 109 110 |
# File 'app/helpers/tungsten/form_helper.rb', line 105 def table_form_tag(form = nil) form.style = 'table' if form content_tag :div, class: ['table', 'table-form'] do yield form if block_given? end end |
#tel_input_tag(name, value = nil, options = {}) ⇒ Object
156 157 158 |
# File 'app/helpers/tungsten/form_helper.rb', line 156 def tel_input_tag(name, value = nil, = {}) input_tag(:tel, name, value, ) end |
#text_input_tag(name, value = nil, options = {}) ⇒ Object
148 149 150 |
# File 'app/helpers/tungsten/form_helper.rb', line 148 def text_input_tag(name, value = nil, = {}) input_tag(:text, name, value, ) end |
#textarea_tag(name, value = nil, options = {}, &block) ⇒ Object
160 161 162 |
# File 'app/helpers/tungsten/form_helper.rb', line 160 def textarea_tag(name, value = nil, = {}, &block) input_tag(:textarea, name, value, , &block) end |
#url_input_tag(name, value = nil, options = {}) ⇒ Object
152 153 154 |
# File 'app/helpers/tungsten/form_helper.rb', line 152 def url_input_tag(name, value = nil, = {}) input_tag(:url, name, value, ) end |