Class: SexyForm::Themes::Foundation
- Defined in:
- lib/sexy_form/themes/foundation.rb
Instance Method Summary collapse
- #build_html_error(error:, html_attrs:, field_type:) ⇒ Object
- #build_html_help_text(help_text:, html_attrs:, field_type:) ⇒ Object
- #form_html_attributes(html_attrs:) ⇒ Object
- #input_html_attributes(html_attrs:, field_type:, has_errors:) ⇒ Object
- #label_html_attributes(html_attrs:, field_type:, has_errors:) ⇒ Object
- #wrap_field(field_type:, html_field:, html_label:, html_help_text: nil, html_errors: nil, wrapper_html_attributes:) ⇒ Object
Methods inherited from BaseTheme
Instance Method Details
#build_html_error(error:, html_attrs:, field_type:) ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/sexy_form/themes/foundation.rb', line 55 def build_html_error(error:, html_attrs:, field_type:) html_attrs["class"] = "form-error #{html_attrs["class"]}".strip s = "" s << (html_attrs.empty? ? "<span>" : "<span #{SexyForm.build_html_attr_string(html_attrs)}>") s << "#{error}" s << "</span>" s end |
#build_html_help_text(help_text:, html_attrs:, field_type:) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/sexy_form/themes/foundation.rb', line 45 def build_html_help_text(help_text:, html_attrs:, field_type:) html_attrs["class"] = "help-text #{html_attrs["class"]}".strip s = "" s << (html_attrs.empty? ? "<p>" : "<p #{SexyForm.build_html_attr_string(html_attrs)}>") s << "#{help_text}" s << "</p>" s end |
#form_html_attributes(html_attrs:) ⇒ Object
41 42 43 |
# File 'lib/sexy_form/themes/foundation.rb', line 41 def form_html_attributes(html_attrs:) html_attrs end |
#input_html_attributes(html_attrs:, field_type:, has_errors:) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/sexy_form/themes/foundation.rb', line 25 def input_html_attributes(html_attrs:, field_type:, has_errors:) if has_errors html_attrs["class"] = "is-invalid-input #{html_attrs["class"]}".strip end html_attrs end |
#label_html_attributes(html_attrs:, field_type:, has_errors:) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/sexy_form/themes/foundation.rb', line 33 def label_html_attributes(html_attrs:, field_type:, has_errors:) if has_errors html_attrs["class"] = "is-invalid-label #{html_attrs["class"]}".strip end html_attrs end |
#wrap_field(field_type:, html_field:, html_label:, html_help_text: nil, html_errors: nil, wrapper_html_attributes:) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/sexy_form/themes/foundation.rb', line 5 def wrap_field(field_type:, html_field:, html_label:, html_help_text: nil, html_errors: nil, wrapper_html_attributes:) s = "" attr_str = SexyForm.build_html_attr_string(wrapper_html_attributes) s << "#{attr_str.empty? ? "<div>" : "<div #{attr_str}>"}" if !["checkbox", "radio"].include?(field_type) && html_label s << html_label.sub("</label>", "#{html_field}</label>") else s << "#{html_field}" s << "#{html_label}" end s << "#{html_help_text}" s << html_errors.join if html_errors s << "</div>" s end |