Sha256: 95ba41b83303f80694bb0fef03fde62c7c02d1fc4b96eb12fea94ff013aea34e

Contents?: true

Size: 1.42 KB

Versions: 2

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true

require_relative '../../components/govuk/form_group'

module CCS
  module FrontendHelpers
    module GovUKFrontend
      # = GOV.UK FormGroup
      #
      # This helper is used for generating the form group component from the Government Design Systems

      module FormGroup
        # Generates the HTML for the GOV.UK Warning text component
        #
        # @param (see CCS::Components::GovUK::FormGroup#initialize)
        #
        # @option options [String] :classes additional CSS classes for the form group HTML
        # @option options  [ActiveModel] :model (nil) model that will be used to find an error message
        # @option options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
        #
        # @yield (see CCS::Components::GovUK::FormGroup#render)
        #
        # @yieldparam (see CCS::Components::GovUK::FormGroup#render)
        #
        # @return (see CCS::Components::GovUK::FormGroup#render)

        def govuk_form_group(attribute, **options, &)
          error_message = if options[:model]
                            options[:model].errors[attribute].first
                          else
                            options[:error_message]
                          end

          Components::GovUK::FormGroup.new(context: self, attribute: attribute, error_message: error_message, **options).render(&)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ccs-frontend_helpers-2.1.0 lib/ccs/frontend_helpers/govuk_frontend/form_group.rb
ccs-frontend_helpers-2.0.0 lib/ccs/frontend_helpers/govuk_frontend/form_group.rb