Module: Katalyst::GOVUK::FormBuilder::Builder
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/katalyst/govuk/form_builder/builder.rb
Instance Method Summary collapse
-
#fieldset_context ⇒ Object
Keep track of whether we are inside a fieldset This allows labels to default to bold (“s”) normally but use the default otherwise.
-
#govuk_check_box_field(attribute_name, value = 1, unchecked_value = 0, small: true, hint: {}, label: {}, link_errors: false) ⇒ ActiveSupport::SafeBuffer
Generates a check box within a fieldset to be used as a boolean toggle for a single attribute.
-
#govuk_combobox(attribute_name, options_or_src = [], options: {}, label: {}, hint: {}, form_group: {}, caption: {}, before_input: nil, after_input: nil) ⇒ ActiveSupport::SafeBuffer
Generates a
comboboxelement that uses Hotwire Combobox to generate a combobox selection element. -
#govuk_document_field(attribute_name, label: {}, caption: {}, hint: {}, form_group: {}, mime_types: config.document_mime_types) ⇒ Object
Generates a file input element for uploading documents.
-
#govuk_enum_check_boxes(attribute_name) ⇒ Object
Generates a checkbox fieldset for an enum defined in the model.
-
#govuk_enum_radio_buttons(attribute_name) ⇒ Object
Generates a radio buttons fieldset for an enum defined in the model.
-
#govuk_enum_select(attribute_name) ⇒ Object
Generates a select for an enum defined in the model.
-
#govuk_image_field(attribute_name, label: {}, caption: {}, hint: {}, form_group: {}, mime_types: config.image_mime_types) ⇒ ActiveSupport::SafeBuffer
Generates a file input element with a preview for uploading images.
-
#govuk_rich_text_area(attribute_name, hint: {}, label: {}, caption: {}, form_group: {}) ⇒ ActiveSupport::SafeBuffer
Generates a pair of
trix-toolbarandtrix-editorelements with a label, optional hint.
Instance Method Details
#fieldset_context ⇒ Object
Keep track of whether we are inside a fieldset This allows labels to default to bold (“s”) normally but use the default otherwise
326 327 328 |
# File 'lib/katalyst/govuk/form_builder/builder.rb', line 326 def fieldset_context @fieldset_context ||= [] end |
#govuk_check_box_field(attribute_name, value = 1, unchecked_value = 0, small: true, hint: {}, label: {}, link_errors: false) ⇒ ActiveSupport::SafeBuffer
Generates a check box within a fieldset to be used as a boolean toggle for a single attribute. The values are 1 (toggled on), and 0 (toggled off).
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/katalyst/govuk/form_builder/builder.rb', line 120 def govuk_check_box_field(attribute_name, value = 1, unchecked_value = 0, small: true, hint: {}, label: {}, link_errors: false, **, &) govuk_check_boxes_fieldset(attribute_name, legend: nil, multiple: false, small:) do fieldset_context.pop # undo push from fieldset extension, labels should be bold unless already nested checkbox = govuk_check_box(attribute_name, value, unchecked_value, hint:, label:, link_errors:, multiple: false, exclusive: false, **, &) fieldset_context.push attribute_name # restore push from fieldset checkbox end end |
#govuk_combobox(attribute_name, options_or_src = [], options: {}, label: {}, hint: {}, form_group: {}, caption: {}, before_input: nil, after_input: nil) ⇒ ActiveSupport::SafeBuffer
Generates a combobox element that uses Hotwire Combobox to generate a combobox selection element.
250 251 252 253 254 255 256 |
# File 'lib/katalyst/govuk/form_builder/builder.rb', line 250 def govuk_combobox(attribute_name, = [], options: {}, label: {}, hint: {}, form_group: {}, caption: {}, before_input: nil, after_input: nil, **, &) Elements::Combobox.new( self, object_name, attribute_name, , options:, label:, hint:, form_group:, caption:, before_input:, after_input:, **, & ).html end |
#govuk_document_field(attribute_name, label: {}, caption: {}, hint: {}, form_group: {}, mime_types: config.document_mime_types) ⇒ Object
Generates a file input element for uploading documents.
263 264 265 266 267 268 269 270 271 272 273 274 |
# File 'lib/katalyst/govuk/form_builder/builder.rb', line 263 def govuk_document_field(attribute_name, label: {}, caption: {}, hint: {}, form_group: {}, mime_types: config.document_mime_types, **, &) Elements::Document.new( self, object_name, attribute_name, label:, caption:, hint:, form_group:, mime_types:, **, & ).html end |
#govuk_enum_check_boxes(attribute_name) ⇒ Object
Generates a checkbox fieldset for an enum defined in the model.
147 148 149 150 |
# File 'lib/katalyst/govuk/form_builder/builder.rb', line 147 def govuk_enum_check_boxes(attribute_name, **, &) govuk_collection_check_boxes(attribute_name, enum_values(attribute_name), :itself, enum_labels_for(attribute_name), **, &) end |
#govuk_enum_radio_buttons(attribute_name) ⇒ Object
Generates a radio buttons fieldset for an enum defined in the model.
154 155 156 157 |
# File 'lib/katalyst/govuk/form_builder/builder.rb', line 154 def (attribute_name, **, &) (attribute_name, enum_values(attribute_name), :itself, enum_labels_for(attribute_name), **, &) end |
#govuk_enum_select(attribute_name) ⇒ Object
Generates a select for an enum defined in the model.
138 139 140 141 |
# File 'lib/katalyst/govuk/form_builder/builder.rb', line 138 def govuk_enum_select(attribute_name, **, &) govuk_collection_select(attribute_name, enum_values(attribute_name), :itself, enum_labels_for(attribute_name), **, &) end |
#govuk_image_field(attribute_name, label: {}, caption: {}, hint: {}, form_group: {}, mime_types: config.image_mime_types) ⇒ ActiveSupport::SafeBuffer
Generates a file input element with a preview for uploading images.
311 312 313 314 315 316 317 318 319 320 321 322 |
# File 'lib/katalyst/govuk/form_builder/builder.rb', line 311 def govuk_image_field(attribute_name, label: {}, caption: {}, hint: {}, form_group: {}, mime_types: config.image_mime_types, **, &) Elements::Image.new( self, object_name, attribute_name, label:, caption:, hint:, form_group:, mime_types:, **, & ).html end |
#govuk_rich_text_area(attribute_name, hint: {}, label: {}, caption: {}, form_group: {}) ⇒ ActiveSupport::SafeBuffer
Generates a pair of trix-toolbar and trix-editor elements with a label, optional hint. Requires action-text to be correctly setup in the application
205 206 207 208 209 210 |
# File 'lib/katalyst/govuk/form_builder/builder.rb', line 205 def govuk_rich_text_area(attribute_name, hint: {}, label: {}, caption: {}, form_group: {}, **, &) Elements::RichTextArea.new( self, object_name, attribute_name, hint:, label:, caption:, form_group:, **, & ).html end |