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: {}) ⇒ 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. -
#govuk_time_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil, extra_letter_spacing: false, form_group: {}, prefix_text: nil, suffix_text: nil) ⇒ ActiveSupport::SafeBuffer
Generates a input of type
time.
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
365 366 367 |
# File 'lib/katalyst/govuk/form_builder/builder.rb', line 365 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).
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/katalyst/govuk/form_builder/builder.rb', line 165 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: {}) ⇒ ActiveSupport::SafeBuffer
Generates a combobox element that uses Hotwire Combobox to generate a combobox selection element.
291 292 293 294 295 |
# File 'lib/katalyst/govuk/form_builder/builder.rb', line 291 def govuk_combobox(attribute_name, = [], options: {}, label: {}, hint: {}, form_group: {}, caption: {}, **, &) Elements::Combobox.new(self, object_name, attribute_name, , options:, label:, hint:, form_group:, caption:, **, &).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.
302 303 304 305 306 307 308 309 310 311 312 313 |
# File 'lib/katalyst/govuk/form_builder/builder.rb', line 302 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.
192 193 194 195 |
# File 'lib/katalyst/govuk/form_builder/builder.rb', line 192 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.
199 200 201 202 |
# File 'lib/katalyst/govuk/form_builder/builder.rb', line 199 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.
183 184 185 186 |
# File 'lib/katalyst/govuk/form_builder/builder.rb', line 183 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.
350 351 352 353 354 355 356 357 358 359 360 361 |
# File 'lib/katalyst/govuk/form_builder/builder.rb', line 350 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
250 251 252 253 254 255 |
# File 'lib/katalyst/govuk/form_builder/builder.rb', line 250 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 |
#govuk_time_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil, extra_letter_spacing: false, form_group: {}, prefix_text: nil, suffix_text: nil) ⇒ ActiveSupport::SafeBuffer
Generates a input of type time
132 133 134 135 136 137 |
# File 'lib/katalyst/govuk/form_builder/builder.rb', line 132 def govuk_time_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil, extra_letter_spacing: false, form_group: {}, prefix_text: nil, suffix_text: nil, **, &) Elements::Time.new(self, object_name, attribute_name, hint:, label:, caption:, width:, extra_letter_spacing:, form_group:, prefix_text:, suffix_text:, **, &).html end |