Module: GOVUKDesignSystemFormBuilder::BuilderHelper

Defined in:
lib/govuk_design_system_formbuilder/builder_helper.rb

Overview

NOTE: this is currently considered experimental, it’s likely to change based on feedback.

BuilderHelper contains methods that expose the form builder’s functionality externally. The objectives are to allow:

  • rendering the error summary outside of the form

  • setting the id of custom form elements (rich text editors, date pickers, sliders, etc) using the formbuilder’s internal logic, allowing them to be linked from the error summary

Instance Method Summary collapse

Instance Method Details

#govuk_error_summary(object, object_name = nil, *args, **kwargs, &block) ⇒ Object

Renders an error summary

Examples:

= govuk_error_summary(@registration)

Options Hash (*args):

  • options (Array)

    passed through to the builder’s #govuk_error_summary

Options Hash (**kwargs):

  • keyword (Hash)

    options passed through to the builder’s #govuk_error_summary

See Also:



45
46
47
48
49
# File 'lib/govuk_design_system_formbuilder/builder_helper.rb', line 45

def govuk_error_summary(object, object_name = nil, *args, **kwargs, &block)
  (object_name = retrieve_object_name(object)) if object_name.nil?

  proxy_builder(object, object_name, self, {}).govuk_error_summary(*args, **kwargs, &block)
end

#govuk_field_id(object, attribute_name, object_name = nil, value: nil, link_errors: true) ⇒ Object

Returns the form builder generated id for an object’s attribute, allowing users to force their custom element ids to match those that’ll be generated by the error summary.



26
27
28
29
30
# File 'lib/govuk_design_system_formbuilder/builder_helper.rb', line 26

def govuk_field_id(object, attribute_name, object_name = nil, value: nil, link_errors: true)
  (object_name = retrieve_object_name(object)) if object_name.nil?

  proxy_base(object, object_name, attribute_name, value:).field_id(link_errors:)
end