Module: GOVUKDesignSystemFormBuilder::Builder

Included in:
Koi::FormBuilder
Defined in:
lib/govuk_design_system_formbuilder/elements/image.rb,
lib/govuk_design_system_formbuilder/elements/document.rb

Instance Method Summary collapse

Instance Method Details

#govuk_document_field(attribute_name, label: {}, caption: {}, hint: {}, form_group: {}, mime_types: Koi.config.document_mime_types, **kwargs, &block) ⇒ Object

Generates a div element with an input with type=file with a label, optional hint.

Examples:

A upload field with label as a proc

= f.govuk_document_field :data, label: -> { tag.h3('Upload your document') }


56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/govuk_design_system_formbuilder/elements/document.rb', line 56

def govuk_document_field(attribute_name,
                         label: {},
                         caption: {},
                         hint: {},
                         form_group: {},
                         mime_types: Koi.config.document_mime_types,
                         **kwargs,
                         &block)
  Elements::Document.new(
    self, object_name, attribute_name, label:, caption:, hint:, form_group:, mime_types:, **kwargs, &block
  ).html
end

#govuk_image_field(attribute_name, label: {}, caption: {}, hint: {}, form_group: {}, mime_types: Koi.config.image_mime_types, **kwargs, &block) ⇒ ActiveSupport::SafeBuffer

Generates a div element to preview uploaded images and an input with type=file with a label, optional hint.

Examples:

An image field with injected content

= f.govuk_image_field :incident_image,
  label: { text: 'Attach a picture of the incident' } do

  p.govuk-inset-text
    | If you don't know exactly leave this section blank

A image upload field with label as a proc

= f.govuk_image_field :image, label: -> { tag.h3('Upload your image') }

Parameters:

  • attribute_name (Symbol)

    The name of the attribute

  • hint (Hash, Proc) (defaults to: {})

    The content of the hint. No hint will be added if ‘text’ is left nil. When a Proc is supplied the hint will be wrapped in a div instead of a span

  • label (Hash, Proc) (defaults to: {})

    configures or sets the associated label content

  • caption (Hash) (defaults to: {})

    configures or sets the caption content which is inserted above the label

  • form_group (Hash) (defaults to: {})

    configures the form group

  • block (Block)

    arbitrary HTML that will be rendered between the hint and the input

  • kwargs (Hash)

    a customizable set of options

Options Hash (label:):

  • text (String)

    the label text

  • size (String)

    the size of the label font, can be xl, l, m, s or nil

  • tag (Symbol, String)

    the label’s wrapper tag, intended to allow labels to act as page headings

  • hidden (Boolean)

    control the visibility of the label. Hidden labels will still be read by screen readers

  • kwargs (Hash)

    additional arguments are applied as attributes on the label element

Options Hash (caption:):

  • text (String)

    the caption text

  • size (String)

    the size of the caption, can be xl, l or m. Defaults to m

  • kwargs (Hash)

    additional arguments are applied as attributes on the caption span element

Options Hash (hint:):

  • text (String)

    the hint text

  • kwargs (Hash)

    additional arguments are applied as attributes to the hint

Options Hash (form_group:):

  • classes (Array, String)

    sets the form group’s classes

  • kwargs (Hash)

    additional attributes added to the form group

Options Hash (**kwargs):

  • kwargs (Hash)

    additional arguments are applied as attributes to the input element.

Returns:

  • (ActiveSupport::SafeBuffer)

    HTML output



86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/govuk_design_system_formbuilder/elements/image.rb', line 86

def govuk_image_field(attribute_name,
                      label: {},
                      caption: {},
                      hint: {},
                      form_group: {},
                      mime_types: Koi.config.image_mime_types,
                      **kwargs,
                      &block)
  Elements::Image.new(
    self, object_name, attribute_name, label:, caption:, hint:, form_group:, mime_types:, **kwargs, &block
  ).html
end