Module: Katalyst::GOVUK::FormBuilder::Builder
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/helpers/katalyst/govuk/form_builder/builder.rb
Instance Method Summary collapse
-
#attachment_preview_url(representation) ⇒ String?
URL for an attachment preview.
-
#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_attachment_field(attribute_name, label: {}, caption: {}, hint: {}, form_group: {}, before_input: nil, after_input: nil, choose_files_button_text: nil, drop_instruction_text: nil, multiple_files_chosen_text: nil, multiple_files_chosen_one_text: nil, multiple_files_chosen_other_text: nil, no_file_chosen_text: nil, entered_drop_zone_text: nil, left_drop_zone_text: nil, upload_succeeded_text: nil, upload_failed_text: nil, retry_button_text: nil, file_removed_text: nil, remove_button_text: nil, remove_button_content_text: nil, direct_upload: true, direct_upload_url: (self.direct_upload_url if direct_upload)) ⇒ Object
Generates an input of type
filewith active storage and preview support. -
#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_textarea(attribute_name, hint: {}, label: {}, caption: {}, form_group: {}) ⇒ ActiveSupport::SafeBuffer
(also: #govuk_rich_text_area)
Generates a pair of
trix-toolbarandtrix-editorelements with a label, optional hint.
Instance Method Details
#attachment_preview_url(representation) ⇒ String?
URL for an attachment preview. ActiveStorage's representation route lives in the application's route set, so engine-mounted forms resolve it through main_app. Returns nil when no route is available, in which case the figure renders without a preview.
475 476 477 478 479 480 481 |
# File 'app/helpers/katalyst/govuk/form_builder/builder.rb', line 475 def (representation) if @template.respond_to?(:rails_representation_path) @template.rails_representation_path(representation) elsif @template.respond_to?(:main_app) && @template.main_app.respond_to?(:rails_representation_path) @template.main_app.rails_representation_path(representation) end end |
#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
464 465 466 |
# File 'app/helpers/katalyst/govuk/form_builder/builder.rb', line 464 def fieldset_context @fieldset_context ||= [] end |
#govuk_attachment_field(attribute_name, label: {}, caption: {}, hint: {}, form_group: {}, before_input: nil, after_input: nil, choose_files_button_text: nil, drop_instruction_text: nil, multiple_files_chosen_text: nil, multiple_files_chosen_one_text: nil, multiple_files_chosen_other_text: nil, no_file_chosen_text: nil, entered_drop_zone_text: nil, left_drop_zone_text: nil, upload_succeeded_text: nil, upload_failed_text: nil, retry_button_text: nil, file_removed_text: nil, remove_button_text: nil, remove_button_content_text: nil, direct_upload: true, direct_upload_url: (self.direct_upload_url if direct_upload)) ⇒ Object
Generates an input of type file with active storage and preview support.
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 |
# File 'app/helpers/katalyst/govuk/form_builder/builder.rb', line 327 def ( attribute_name, label: {}, caption: {}, hint: {}, form_group: {}, before_input: nil, after_input: nil, choose_files_button_text: nil, drop_instruction_text: nil, multiple_files_chosen_text: nil, multiple_files_chosen_one_text: nil, multiple_files_chosen_other_text: nil, no_file_chosen_text: nil, entered_drop_zone_text: nil, left_drop_zone_text: nil, upload_succeeded_text: nil, upload_failed_text: nil, retry_button_text: nil, file_removed_text: nil, remove_button_text: nil, remove_button_content_text: nil, direct_upload: true, direct_upload_url: (self.direct_upload_url if direct_upload), **, & ) Elements::Attachment.new( self, object_name, attribute_name, label:, caption:, hint:, form_group:, before_input:, after_input:, direct_upload_url:, choose_files_button_text:, drop_instruction_text:, multiple_files_chosen_text:, multiple_files_chosen_one_text:, multiple_files_chosen_other_text:, no_file_chosen_text:, entered_drop_zone_text:, left_drop_zone_text:, upload_succeeded_text:, upload_failed_text:, retry_button_text:, file_removed_text:, remove_button_text:, remove_button_content_text:, **, & ).html 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).
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'app/helpers/katalyst/govuk/form_builder/builder.rb', line 123 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.
246 247 248 249 250 251 252 |
# File 'app/helpers/katalyst/govuk/form_builder/builder.rb', line 246 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.
389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 |
# File 'app/helpers/katalyst/govuk/form_builder/builder.rb', line 389 def govuk_document_field(attribute_name, label: {}, caption: {}, hint: {}, form_group: {}, mime_types: config.document_mime_types, **, &) if config.use_legacy_file_fields Elements::Document.new( self, object_name, attribute_name, label:, caption:, hint:, form_group:, mime_types:, **, & ).html else ( attribute_name, label:, caption:, hint:, form_group:, accept: mime_types&.join(","), **, & ) end end |
#govuk_enum_check_boxes(attribute_name) ⇒ Object
Generates a checkbox fieldset for an enum defined in the model.
150 151 152 153 |
# File 'app/helpers/katalyst/govuk/form_builder/builder.rb', line 150 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.
157 158 159 160 |
# File 'app/helpers/katalyst/govuk/form_builder/builder.rb', line 157 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.
141 142 143 144 |
# File 'app/helpers/katalyst/govuk/form_builder/builder.rb', line 141 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.
443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 |
# File 'app/helpers/katalyst/govuk/form_builder/builder.rb', line 443 def govuk_image_field(attribute_name, label: {}, caption: {}, hint: {}, form_group: {}, mime_types: config.image_mime_types, **, &) if config.use_legacy_file_fields Elements::Image.new( self, object_name, attribute_name, label:, caption:, hint:, form_group:, mime_types:, **, & ).html else ( attribute_name, label:, caption:, hint:, form_group:, accept: mime_types&.join(","), **, & ) end end |
#govuk_rich_textarea(attribute_name, hint: {}, label: {}, caption: {}, form_group: {}) ⇒ ActiveSupport::SafeBuffer Also known as: govuk_rich_text_area
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
200 201 202 203 204 205 |
# File 'app/helpers/katalyst/govuk/form_builder/builder.rb', line 200 def govuk_rich_textarea(attribute_name, hint: {}, label: {}, caption: {}, form_group: {}, **, &) Elements::RichTextarea.new( self, object_name, attribute_name, hint:, label:, caption:, form_group:, **, & ).html end |