Class: DesignSystem::Nhsuk::FormBuilder
- Inherits:
-
Govuk::FormBuilder
- Object
- ActionView::Helpers::FormBuilder
- Generic::FormBuilder
- Govuk::FormBuilder
- DesignSystem::Nhsuk::FormBuilder
- Defined in:
- lib/design_system/nhsuk/form_builder.rb
Overview
The NHS version of the form builder
Instance Method Summary collapse
-
#ds_hidden_field(method, options = {}) ⇒ Object
Same interface as ActionView::Helpers::FormHelper.hidden_field, but with label automatically added and takes a show_text option.
- #ds_password_field(method, options = {}) ⇒ Object
- #show_password_button ⇒ Object
Methods inherited from Govuk::FormBuilder
#ds_check_box, #ds_check_boxes_fieldset, #ds_collection_check_boxes, #ds_collection_radio_buttons, #ds_collection_select, #ds_date_field, #ds_email_field, #ds_error_summary, #ds_field_set_tag, #ds_file_field, #ds_label, #ds_number_field, #ds_phone_field, #ds_radio_button, #ds_radio_buttons_fieldset, #ds_select, #ds_submit, #ds_text_area, #ds_text_field, #ds_url_field, #initialize
Methods inherited from Generic::FormBuilder
Methods included from Helpers::CssHelper
Constructor Details
This class inherits a constructor from DesignSystem::Govuk::FormBuilder
Instance Method Details
#ds_hidden_field(method, options = {}) ⇒ Object
Same interface as ActionView::Helpers::FormHelper.hidden_field, but with label automatically added and takes a show_text option
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/design_system/nhsuk/form_builder.rb', line 7 def ds_hidden_field(method, = {}) @brand = config.brand [:class] = Array([:class]) [:class] << "#{@brand}-u-visually-hidden" label_hash = .delete(:label) || {} label = ds_label(method, label_hash) show_text = .delete(:show_text) content_tag(:div, class: "#{@brand}-form-group") do components = [] components << label if label components << hidden_field(method, **) components << content_tag(:span, show_text, class: "#{@brand}-body-m") if show_text safe_join(components) end end |
#ds_password_field(method, options = {}) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/design_system/nhsuk/form_builder.rb', line 27 def ds_password_field(method, = {}) @brand = config.brand [:id] = govuk_field_id(method, link_errors: true) = (, ["#{@brand}-input", has_errors?(method) ? "#{@brand}-input--error" : nil].compact) hint = .delete(:hint) [:'aria-describedby'] = field_id("#{method}-hint") if hint [:autocomplete] = 'current-password' ['data-ds--show-password-target'] = 'password' .delete('text') form_group_classes = ["#{@brand}-form-group"] form_group_classes << "#{@brand}-form-group--error" if has_errors?(method) content_tag(:div, class: form_group_classes.join(' '), data: { controller: 'ds--show-password', 'ds--show-password-show-text-value': 'Show password', 'ds--show-password-hide-text-value': 'Hide password' }) do ds_label(method, {}) + optional_hint(method, hint) + password_field(method, ) + ' '.html_safe + end end |
#show_password_button ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/design_system/nhsuk/form_builder.rb', line 57 def = { type: 'button', class: "#{@brand}-button #{@brand}-button--secondary", style: 'padding: 8px 10px 7px; margin-bottom: 0px !important', aria: { label: 'Show password' }, data: { 'module' => "#{@brand}-button", 'action' => 'click->ds--show-password#toggle', 'ds--show-password-target' => 'button' } } content_tag(:button, 'Show password', ) end |