Module: GOVUKDesignSystemFormBuilder::Builder
- Included in:
- FormBuilder
- Defined in:
- lib/govuk_design_system_formbuilder/builder.rb
Instance Method Summary collapse
-
#govuk_check_box(attribute_name, value, unchecked_value = false, hint: {}, label: {}, link_errors: false, multiple: true, exclusive: false, **kwargs, &block) ⇒ ActiveSupport::SafeBuffer
Generates a single check box, intended for use within a #govuk_check_boxes_fieldset.
-
#govuk_check_box_divider(text = config.default_check_box_divider_text) ⇒ ActiveSupport::SafeBuffer
Inserts a text divider into a list of check boxes.
-
#govuk_check_boxes_fieldset(attribute_name, legend: {}, caption: {}, hint: {}, small: false, form_group: {}, multiple: true, **kwargs, &block) ⇒ ActiveSupport::SafeBuffer
Generate a fieldset intended to conatain one or more #govuk_check_box.
-
#govuk_collection_check_boxes(attribute_name, collection, value_method, text_method, hint_method = nil, hint: {}, legend: {}, caption: {}, small: false, form_group: {}, include_hidden: config.default_collection_check_boxes_include_hidden, **kwargs, &block) ⇒ ActiveSupport::SafeBuffer
Generate a list of check boxes from a collection.
-
#govuk_collection_radio_buttons(attribute_name, collection, value_method, text_method = nil, hint_method = nil, hint: {}, legend: {}, caption: {}, inline: false, small: false, bold_labels: nil, include_hidden: config.default_collection_radio_buttons_include_hidden, form_group: {}, **kwargs, &block) ⇒ ActiveSupport::SafeBuffer
Generates a radio button for each item in the supplied collection.
-
#govuk_collection_select(attribute_name, collection, value_method, text_method, options: {}, hint: {}, label: {}, caption: {}, form_group: {}, **kwargs, &block) ⇒ ActiveSupport::SafeBuffer
Generates a
selectelement containingoptionfor each member in the provided collection. -
#govuk_date_field(attribute_name, hint: {}, legend: {}, caption: {}, date_of_birth: false, omit_day: false, maxlength_enabled: false, form_group: {}, **kwargs, &block) ⇒ ActiveSupport::SafeBuffer
Generates three inputs for the
day,monthandyearcomponents of a date. -
#govuk_email_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil, extra_letter_spacing: false, form_group: {}, prefix_text: nil, suffix_text: nil, **kwargs, &block) ⇒ ActiveSupport::SafeBuffer
Generates a input of type
email. -
#govuk_error_summary(title = config.default_error_summary_title, presenter: config.default_error_summary_presenter, link_base_errors_to: nil, order: nil, **kwargs, &block) ⇒ Object
Generates a summary of errors in the form, each linking to the corresponding part of the form that contains the error.
-
#govuk_fieldset(legend: { text: 'Fieldset heading' }, caption: {}, described_by: nil, **kwargs, &block) ⇒ ActiveSupport::SafeBuffer
Generates a fieldset containing the contents of the block.
-
#govuk_file_field(attribute_name, label: {}, caption: {}, hint: {}, form_group: {}, **kwargs, &block) ⇒ Object
Generates an input of type
file. -
#govuk_number_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil, extra_letter_spacing: false, form_group: {}, prefix_text: nil, suffix_text: nil, **kwargs, &block) ⇒ ActiveSupport::SafeBuffer
Generates a input of type
number. -
#govuk_password_field(attribute_name, hint: {}, label: {}, width: nil, extra_letter_spacing: false, form_group: {}, caption: {}, prefix_text: nil, suffix_text: nil, **kwargs, &block) ⇒ ActiveSupport::SafeBuffer
Generates a input of type
password. -
#govuk_phone_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil, extra_letter_spacing: false, form_group: {}, prefix_text: nil, suffix_text: nil, **kwargs, &block) ⇒ ActiveSupport::SafeBuffer
Generates a input of type
tel. -
#govuk_radio_button(attribute_name, value, hint: {}, label: {}, link_errors: false, **kwargs, &block) ⇒ ActiveSupport::SafeBuffer
Generates a radio button.
-
#govuk_radio_buttons_fieldset(attribute_name, hint: {}, legend: {}, caption: {}, inline: false, small: false, form_group: {}, **kwargs, &block) ⇒ ActiveSupport::SafeBuffer
Generates a radio button fieldset container and injects the supplied block contents.
-
#govuk_radio_divider(text = config.default_radio_divider_text) ⇒ ActiveSupport::SafeBuffer
Inserts a text divider into a list of radio buttons.
-
#govuk_select(attribute_name, choices = nil, options: {}, label: {}, hint: {}, form_group: {}, caption: {}, **kwargs, &block) ⇒ ActiveSupport::SafeBuffer
Generates a
selectelement containing anoptionfor every choice provided. -
#govuk_submit(text = config.default_submit_button_text, warning: false, secondary: false, prevent_double_click: true, validate: config.default_submit_validate, disabled: false, **kwargs, &block) ⇒ ActiveSupport::SafeBuffer
Generates a submit button, green by default.
-
#govuk_text_area(attribute_name, hint: {}, label: {}, caption: {}, max_words: nil, max_chars: nil, rows: 5, threshold: nil, form_group: {}, **kwargs, &block) ⇒ ActiveSupport::SafeBuffer
Generates a
textareaelement with a label, optional hint. -
#govuk_text_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil, extra_letter_spacing: false, form_group: {}, prefix_text: nil, suffix_text: nil, **kwargs, &block) ⇒ ActiveSupport::SafeBuffer
Generates a input of type
text. -
#govuk_url_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil, extra_letter_spacing: false, form_group: {}, prefix_text: nil, suffix_text: nil, **kwargs, &block) ⇒ ActiveSupport::SafeBuffer
Generates a input of type
url.
Instance Method Details
#govuk_check_box(attribute_name, value, unchecked_value = false, hint: {}, label: {}, link_errors: false, multiple: true, exclusive: false, **kwargs, &block) ⇒ ActiveSupport::SafeBuffer
Generates a single check box, intended for use within a #govuk_check_boxes_fieldset
826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 |
# File 'lib/govuk_design_system_formbuilder/builder.rb', line 826 def govuk_check_box(attribute_name, value, unchecked_value = false, hint: {}, label: {}, link_errors: false, multiple: true, exclusive: false, **kwargs, &block) Elements::CheckBoxes::FieldsetCheckBox.new( self, object_name, attribute_name, value, unchecked_value, hint: hint, label: label, link_errors: link_errors, multiple: multiple, exclusive: exclusive, **kwargs, &block ).html end |
#govuk_check_box_divider(text = config.default_check_box_divider_text) ⇒ ActiveSupport::SafeBuffer
This should only be used from within a #govuk_check_boxes_fieldset
Inserts a text divider into a list of check boxes
851 852 853 |
# File 'lib/govuk_design_system_formbuilder/builder.rb', line 851 def govuk_check_box_divider(text = config.default_check_box_divider_text) tag.div(text, class: %w(govuk-checkboxes__divider)) end |
#govuk_check_boxes_fieldset(attribute_name, legend: {}, caption: {}, hint: {}, small: false, form_group: {}, multiple: true, **kwargs, &block) ⇒ ActiveSupport::SafeBuffer
To ensure the #govuk_error_summary link functions correctly ensure the first #govuk_check_box is set to link_errors: true
Generate a fieldset intended to conatain one or more #govuk_check_box
780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 |
# File 'lib/govuk_design_system_formbuilder/builder.rb', line 780 def govuk_check_boxes_fieldset(attribute_name, legend: {}, caption: {}, hint: {}, small: false, form_group: {}, multiple: true, **kwargs, &block) Containers::CheckBoxesFieldset.new( self, object_name, attribute_name, hint: hint, legend: legend, caption: caption, small: small, form_group: form_group, multiple: multiple, **kwargs, &block ).html end |
#govuk_collection_check_boxes(attribute_name, collection, value_method, text_method, hint_method = nil, hint: {}, legend: {}, caption: {}, small: false, form_group: {}, include_hidden: config.default_collection_check_boxes_include_hidden, **kwargs, &block) ⇒ ActiveSupport::SafeBuffer
Generate a list of check boxes from a collection
722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 |
# File 'lib/govuk_design_system_formbuilder/builder.rb', line 722 def govuk_collection_check_boxes(attribute_name, collection, value_method, text_method, hint_method = nil, hint: {}, legend: {}, caption: {}, small: false, form_group: {}, include_hidden: config.default_collection_check_boxes_include_hidden, **kwargs, &block) Elements::CheckBoxes::Collection.new( self, object_name, attribute_name, collection, value_method: value_method, text_method: text_method, hint_method: hint_method, hint: hint, legend: legend, caption: caption, small: small, form_group: form_group, include_hidden: include_hidden, **kwargs, &block ).html end |
#govuk_collection_radio_buttons(attribute_name, collection, value_method, text_method = nil, hint_method = nil, hint: {}, legend: {}, caption: {}, inline: false, small: false, bold_labels: nil, include_hidden: config.default_collection_radio_buttons_include_hidden, form_group: {}, **kwargs, &block) ⇒ ActiveSupport::SafeBuffer
Unlike the Rails #collection_radio_buttons helper, this version can also insert hints per item in the collection by supplying a :hint_method
:bold_labels, is nil (falsy) by default. When a :hint_method is provided it will become true to make the label stand out more from the hint. The choice can be overridden with true or false.
Generates a radio button for each item in the supplied collection
543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 |
# File 'lib/govuk_design_system_formbuilder/builder.rb', line 543 def (attribute_name, collection, value_method, text_method = nil, hint_method = nil, hint: {}, legend: {}, caption: {}, inline: false, small: false, bold_labels: nil, include_hidden: config., form_group: {}, **kwargs, &block) Elements::Radios::Collection.new( self, object_name, attribute_name, collection, value_method: value_method, text_method: text_method, hint_method: hint_method, hint: hint, legend: legend, caption: caption, inline: inline, small: small, bold_labels: bold_labels, form_group: form_group, include_hidden: include_hidden, **kwargs, &block ).html end |
#govuk_collection_select(attribute_name, collection, value_method, text_method, options: {}, hint: {}, label: {}, caption: {}, form_group: {}, **kwargs, &block) ⇒ ActiveSupport::SafeBuffer
Generates a select element containing option for each member in the provided collection
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 |
# File 'lib/govuk_design_system_formbuilder/builder.rb', line 419 def govuk_collection_select(attribute_name, collection, value_method, text_method, options: {}, hint: {}, label: {}, caption: {}, form_group: {}, **kwargs, &block) Elements::CollectionSelect.new( self, object_name, attribute_name, collection, value_method: value_method, text_method: text_method, hint: hint, label: label, caption: caption, options: , form_group: form_group, **kwargs, &block ).html end |
#govuk_date_field(attribute_name, hint: {}, legend: {}, caption: {}, date_of_birth: false, omit_day: false, maxlength_enabled: false, form_group: {}, **kwargs, &block) ⇒ ActiveSupport::SafeBuffer
When using this input be aware that Rails’s multiparam time and date handling falls foul of this bug, so incorrect dates like 2019-09-31 will be ‘rounded’ up to 2019-10-01.
When using this input values will be retrieved from the attribute if it is a Date object or a multiparam date hash
Generates three inputs for the day, month and year components of a date
933 934 935 |
# File 'lib/govuk_design_system_formbuilder/builder.rb', line 933 def govuk_date_field(attribute_name, hint: {}, legend: {}, caption: {}, date_of_birth: false, omit_day: false, maxlength_enabled: false, form_group: {}, **kwargs, &block) Elements::Date.new(self, object_name, attribute_name, hint: hint, legend: legend, caption: caption, date_of_birth: date_of_birth, omit_day: omit_day, maxlength_enabled: maxlength_enabled, form_group: form_group, **kwargs, &block).html end |
#govuk_email_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil, extra_letter_spacing: false, form_group: {}, prefix_text: nil, suffix_text: nil, **kwargs, &block) ⇒ ActiveSupport::SafeBuffer
Generates a input of type email
161 162 163 |
# File 'lib/govuk_design_system_formbuilder/builder.rb', line 161 def govuk_email_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil, extra_letter_spacing: false, form_group: {}, prefix_text: nil, suffix_text: nil, **kwargs, &block) Elements::Inputs::Email.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, width: width, extra_letter_spacing: extra_letter_spacing, form_group: form_group, prefix_text: prefix_text, suffix_text: suffix_text, **kwargs, &block).html end |
#govuk_error_summary(title = config.default_error_summary_title, presenter: config.default_error_summary_presenter, link_base_errors_to: nil, order: nil, **kwargs, &block) ⇒ Object
Only the first error in the #errors array for each attribute will be included.
Generates a summary of errors in the form, each linking to the corresponding part of the form that contains the error
963 964 965 |
# File 'lib/govuk_design_system_formbuilder/builder.rb', line 963 def govuk_error_summary(title = config.default_error_summary_title, presenter: config.default_error_summary_presenter, link_base_errors_to: nil, order: nil, **kwargs, &block) Elements::ErrorSummary.new(self, object_name, title, link_base_errors_to: link_base_errors_to, order: order, presenter: presenter, **kwargs, &block).html end |
#govuk_fieldset(legend: { text: 'Fieldset heading' }, caption: {}, described_by: nil, **kwargs, &block) ⇒ ActiveSupport::SafeBuffer
Generates a fieldset containing the contents of the block
996 997 998 |
# File 'lib/govuk_design_system_formbuilder/builder.rb', line 996 def govuk_fieldset(legend: { text: 'Fieldset heading' }, caption: {}, described_by: nil, **kwargs, &block) Containers::Fieldset.new(self, legend: legend, caption: caption, described_by: described_by, **kwargs, &block).html end |
#govuk_file_field(attribute_name, label: {}, caption: {}, hint: {}, form_group: {}, **kwargs, &block) ⇒ Object
Remember to set multipart: true when creating a form with file uploads, see the Rails documentation for more information
Generates an input of type file
1037 1038 1039 |
# File 'lib/govuk_design_system_formbuilder/builder.rb', line 1037 def govuk_file_field(attribute_name, label: {}, caption: {}, hint: {}, form_group: {}, **kwargs, &block) Elements::File.new(self, object_name, attribute_name, label: label, caption: caption, hint: hint, form_group: form_group, **kwargs, &block).html end |
#govuk_number_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil, extra_letter_spacing: false, form_group: {}, prefix_text: nil, suffix_text: nil, **kwargs, &block) ⇒ ActiveSupport::SafeBuffer
Generates a input of type number
319 320 321 |
# File 'lib/govuk_design_system_formbuilder/builder.rb', line 319 def govuk_number_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil, extra_letter_spacing: false, form_group: {}, prefix_text: nil, suffix_text: nil, **kwargs, &block) Elements::Inputs::Number.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, width: width, extra_letter_spacing: extra_letter_spacing, form_group: form_group, prefix_text: prefix_text, suffix_text: suffix_text, **kwargs, &block).html end |
#govuk_password_field(attribute_name, hint: {}, label: {}, width: nil, extra_letter_spacing: false, form_group: {}, caption: {}, prefix_text: nil, suffix_text: nil, **kwargs, &block) ⇒ ActiveSupport::SafeBuffer
Generates a input of type password
212 213 214 |
# File 'lib/govuk_design_system_formbuilder/builder.rb', line 212 def govuk_password_field(attribute_name, hint: {}, label: {}, width: nil, extra_letter_spacing: false, form_group: {}, caption: {}, prefix_text: nil, suffix_text: nil, **kwargs, &block) Elements::Inputs::Password.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, width: width, extra_letter_spacing: extra_letter_spacing, form_group: form_group, prefix_text: prefix_text, suffix_text: suffix_text, **kwargs, &block).html end |
#govuk_phone_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil, extra_letter_spacing: false, form_group: {}, prefix_text: nil, suffix_text: nil, **kwargs, &block) ⇒ ActiveSupport::SafeBuffer
Generates a input of type tel
109 110 111 |
# File 'lib/govuk_design_system_formbuilder/builder.rb', line 109 def govuk_phone_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil, extra_letter_spacing: false, form_group: {}, prefix_text: nil, suffix_text: nil, **kwargs, &block) Elements::Inputs::Phone.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, width: width, extra_letter_spacing: extra_letter_spacing, form_group: form_group, prefix_text: prefix_text, suffix_text: suffix_text, **kwargs, &block).html end |
#govuk_radio_button(attribute_name, value, hint: {}, label: {}, link_errors: false, **kwargs, &block) ⇒ ActiveSupport::SafeBuffer
This should only be used from within a #govuk_radio_buttons_fieldset
Generates a radio button
645 646 647 |
# File 'lib/govuk_design_system_formbuilder/builder.rb', line 645 def (attribute_name, value, hint: {}, label: {}, link_errors: false, **kwargs, &block) Elements::Radios::FieldsetRadioButton.new(self, object_name, attribute_name, value, hint: hint, label: label, link_errors: link_errors, **kwargs, &block).html end |
#govuk_radio_buttons_fieldset(attribute_name, hint: {}, legend: {}, caption: {}, inline: false, small: false, form_group: {}, **kwargs, &block) ⇒ ActiveSupport::SafeBuffer
The intention is to use #govuk_radio_button and #govuk_radio_divider within the passed-in block
To ensure the #govuk_error_summary link functions correctly ensure the first #govuk_radio_button is set to link_errors: true
Generates a radio button fieldset container and injects the supplied block contents
613 614 615 |
# File 'lib/govuk_design_system_formbuilder/builder.rb', line 613 def (attribute_name, hint: {}, legend: {}, caption: {}, inline: false, small: false, form_group: {}, **kwargs, &block) Containers::RadioButtonsFieldset.new(self, object_name, attribute_name, hint: hint, legend: legend, caption: caption, inline: inline, small: small, form_group: form_group, **kwargs, &block).html end |
#govuk_radio_divider(text = config.default_radio_divider_text) ⇒ ActiveSupport::SafeBuffer
This should only be used from within a #govuk_radio_buttons_fieldset
Inserts a text divider into a list of radio buttons
657 658 659 |
# File 'lib/govuk_design_system_formbuilder/builder.rb', line 657 def govuk_radio_divider(text = config.default_radio_divider_text) tag.div(text, class: %w(govuk-radios__divider)) end |
#govuk_select(attribute_name, choices = nil, options: {}, label: {}, hint: {}, form_group: {}, caption: {}, **kwargs, &block) ⇒ ActiveSupport::SafeBuffer
Generates a select element containing an option for every choice provided
468 469 470 |
# File 'lib/govuk_design_system_formbuilder/builder.rb', line 468 def govuk_select(attribute_name, choices = nil, options: {}, label: {}, hint: {}, form_group: {}, caption: {}, **kwargs, &block) Elements::Select.new(self, object_name, attribute_name, choices, options: , label: label, hint: hint, form_group: form_group, caption: caption, **kwargs, &block).html end |
#govuk_submit(text = config.default_submit_button_text, warning: false, secondary: false, prevent_double_click: true, validate: config.default_submit_validate, disabled: false, **kwargs, &block) ⇒ ActiveSupport::SafeBuffer
Only the first additional button or link (passed in via a block) will be given the correct left margin, subsequent buttons will need to be manually accounted for
This helper always renders an <button type=‘submit’> tag. Previous versions of this gem rendered a +‘<input type=’submit’>‘ tag instead, but there is a longstanding bug with this approach where the top few pixels don’t initiate a submission when clicked.
Generates a submit button, green by default
884 885 886 |
# File 'lib/govuk_design_system_formbuilder/builder.rb', line 884 def govuk_submit(text = config., warning: false, secondary: false, prevent_double_click: true, validate: config.default_submit_validate, disabled: false, **kwargs, &block) Elements::Submit.new(self, text, warning: warning, secondary: secondary, prevent_double_click: prevent_double_click, validate: validate, disabled: disabled, **kwargs, &block).html end |
#govuk_text_area(attribute_name, hint: {}, label: {}, caption: {}, max_words: nil, max_chars: nil, rows: 5, threshold: nil, form_group: {}, **kwargs, &block) ⇒ ActiveSupport::SafeBuffer
Setting max_chars or max_words will add a caption beneath the textarea with a live count of words or characters
Generates a textarea element with a label, optional hint. Also offers the ability to add the GOV.UK character and word counting components automatically
375 376 377 |
# File 'lib/govuk_design_system_formbuilder/builder.rb', line 375 def govuk_text_area(attribute_name, hint: {}, label: {}, caption: {}, max_words: nil, max_chars: nil, rows: 5, threshold: nil, form_group: {}, **kwargs, &block) Elements::TextArea.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, max_words: max_words, max_chars: max_chars, rows: rows, threshold: threshold, form_group: form_group, **kwargs, &block).html end |
#govuk_text_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil, extra_letter_spacing: false, form_group: {}, prefix_text: nil, suffix_text: nil, **kwargs, &block) ⇒ ActiveSupport::SafeBuffer
Generates a input of type text
55 56 57 |
# File 'lib/govuk_design_system_formbuilder/builder.rb', line 55 def govuk_text_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil, extra_letter_spacing: false, form_group: {}, prefix_text: nil, suffix_text: nil, **kwargs, &block) Elements::Inputs::Text.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, width: width, extra_letter_spacing: extra_letter_spacing, form_group: form_group, prefix_text: prefix_text, suffix_text: suffix_text, **kwargs, &block).html end |
#govuk_url_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil, extra_letter_spacing: false, form_group: {}, prefix_text: nil, suffix_text: nil, **kwargs, &block) ⇒ ActiveSupport::SafeBuffer
Generates a input of type url
264 265 266 |
# File 'lib/govuk_design_system_formbuilder/builder.rb', line 264 def govuk_url_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil, extra_letter_spacing: false, form_group: {}, prefix_text: nil, suffix_text: nil, **kwargs, &block) Elements::Inputs::URL.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, width: width, extra_letter_spacing: extra_letter_spacing, form_group: form_group, prefix_text: prefix_text, suffix_text: suffix_text, **kwargs, &block).html end |