Module: Rad::FormHelper
- Defined in:
- lib/rad/html/helpers/form_helper.rb
Instance Method Summary collapse
- #build_form_model_helper_and_form_options(model_name, model, options = {}) ⇒ Object
-
#check_box_tag(name, checked = false, options = {}) ⇒ Object
Form fields.
-
#error_messages(*errors) ⇒ Object
Errors.
- #field_set_tag(legend = nil, options = {}, &block) ⇒ Object
- #field_with_errors(name, errors, options, field_html) ⇒ Object
- #file_field_tag(name, options = {}) ⇒ Object
-
#form_for(*args, &block) ⇒ Object
Form.
- #form_tag(options = {}, &block) ⇒ Object
- #hidden_field_tag(name, value = '', options = {}) ⇒ Object
- #password_field_tag(name, value = nil, options = {}) ⇒ Object
- #radio_button_tag(name, checked = false, options = {}) ⇒ Object
- #select_tag(name, selected, values, options = {}) ⇒ Object
-
#submit_tag(value, options = {}) ⇒ Object
Other.
- #text_area_tag(name, value = '', options = {}) ⇒ Object
- #text_field_tag(name, value = '', options = {}) ⇒ Object
Instance Method Details
#build_form_model_helper_and_form_options(model_name, model, options = {}) ⇒ Object
14 15 16 17 |
# File 'lib/rad/html/helpers/form_helper.rb', line 14 def model_name, model, = {} model_name.must_be.a String, Symbol return ModelHelper.new(self, self, model_name, model, ), end |
#check_box_tag(name, checked = false, options = {}) ⇒ Object
Form fields
45 46 47 48 49 |
# File 'lib/rad/html/helpers/form_helper.rb', line 45 def check_box_tag name, checked = false, = {} = {type: "checkbox", name: name, value: '1'}.update() [:checked] = "checked" if checked tag_with_style :input, '', end |
#error_messages(*errors) ⇒ Object
Errors
delegate :error_messages, :field_with_errors, to: :form_builder
29 30 31 32 33 |
# File 'lib/rad/html/helpers/form_helper.rb', line 29 def *errors errors = errors.first if errors.size == 1 and errors.first.is_a? Array html = errors.join("<br/>") tag :div, html, class: :error_messages end |
#field_set_tag(legend = nil, options = {}, &block) ⇒ Object
51 52 53 54 55 56 |
# File 'lib/rad/html/helpers/form_helper.rb', line 51 def field_set_tag legend = nil, = {}, &block content = "" content << tag(:legend, legend) unless legend.blank? content << capture(&block) tag_with_style :fieldset, content, end |
#field_with_errors(name, errors, options, field_html) ⇒ Object
35 36 37 38 39 |
# File 'lib/rad/html/helpers/form_helper.rb', line 35 def field_with_errors name, errors, , field_html html = tag :div, errors.join("<br/>"), class: :field_error_messages html << tag(:span, field_html, class: :field_with_errors) html end |
#file_field_tag(name, options = {}) ⇒ Object
58 59 60 |
# File 'lib/rad/html/helpers/form_helper.rb', line 58 def file_field_tag name, = {} text_field_tag name, nil, .update(type: "file") end |
#form_for(*args, &block) ⇒ Object
Form
6 7 8 9 10 11 12 |
# File 'lib/rad/html/helpers/form_helper.rb', line 6 def form_for *args, &block model_helper, = *args form_tag do block.call model_helper if block end end |
#form_tag(options = {}, &block) ⇒ Object
19 20 21 22 |
# File 'lib/rad/html/helpers/form_helper.rb', line 19 def form_tag = {}, &block ['method'] ||= [:method] || 'post' tag :form, , &block end |
#hidden_field_tag(name, value = '', options = {}) ⇒ Object
62 63 64 |
# File 'lib/rad/html/helpers/form_helper.rb', line 62 def hidden_field_tag name, value = '', = {} text_field_tag(name, value, .update(type: "hidden")) end |
#password_field_tag(name, value = nil, options = {}) ⇒ Object
66 67 68 |
# File 'lib/rad/html/helpers/form_helper.rb', line 66 def password_field_tag name, value = nil, = {} text_field_tag(name, value, .update(type: "password")) end |
#radio_button_tag(name, checked = false, options = {}) ⇒ Object
70 71 72 73 74 |
# File 'lib/rad/html/helpers/form_helper.rb', line 70 def name, checked = false, = {} = {type: "radio", name: name, value: '1'}.update() ["checked"] = "checked" if checked tag_with_style :input, '', end |
#select_tag(name, selected, values, options = {}) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/rad/html/helpers/form_helper.rb', line 76 def select_tag name, selected, values, = {} buff = "\n" values.each do |n, v| o = {} o[:value] = v if v o[:selected] = 'selected' if (v || n) == selected buff << tag(:option, n, o) buff << "\n" end tag_with_style :select, buff, {name: name}.update() end |
#submit_tag(value, options = {}) ⇒ Object
Other
101 102 103 |
# File 'lib/rad/html/helpers/form_helper.rb', line 101 def submit_tag value, = {} tag_with_style :input, '', {type: "submit", value: value}.update() end |
#text_area_tag(name, value = '', options = {}) ⇒ Object
93 94 95 |
# File 'lib/rad/html/helpers/form_helper.rb', line 93 def text_area_tag name, value = '', = {} tag_with_style :textarea, value, {name: name}.update() end |
#text_field_tag(name, value = '', options = {}) ⇒ Object
89 90 91 |
# File 'lib/rad/html/helpers/form_helper.rb', line 89 def text_field_tag name, value = '', = {} tag_with_style :input, '', {type: "text", name: name, value: value}.update() end |