Sha256: 2c14d2718f48648d59d7e5e8d5dd9ebfa5771842de264891fc9e9eb9d8165157

Contents?: true

Size: 1.71 KB

Versions: 8

Compression:

Stored size: 1.71 KB

Contents

require_relative '../field'
require_relative '../fieldset'

module CCS
  module Components
    module GovUK
      class Field < Base
        # = GOV.UK Field Inputs
        #
        # This class is used to create a form for a list of fields, e.g. radios or checkboxes.
        # It will wrap the inputs in the form group and then the fieldset and:
        # - display the hint (if there is one)
        # - find and display the error message (if there is one)
        #
        # @!attribute [r] fieldset
        #   @return [Fieldset] The initialised fieldset

        class Inputs < Field
          private

          attr_reader :fieldset

          public

          # @param (see CCS::Components::GovUK::Field#initialize)
          # @param fieldset [Hash] attributes for the fieldset, see {CCS::Components::GovUK::Fieldset#initialize Fieldset#initialize} for more details.
          #
          # @option (see CCS::Components::GovUK::Field#initialize)

          def initialize(attribute:, fieldset:, **options)
            super(attribute: attribute, **options)

            set_described_by(fieldset, @attribute, @error_message, options[:hint])

            @fieldset = Fieldset.new(context: @context, **fieldset)
          end

          # Generates the HTML to wrap arround a GDS form component
          #
          # @yield (see CCS::Components::GovUK::Field#render)
          #
          # @return [ActiveSupport::SafeBuffer]

          def render
            super() do |display_error_message|
              fieldset.render do
                concat(hint.render) if hint
                concat(display_error_message)
                concat(yield)
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
ccs-frontend_helpers-0.1.2 lib/ccs/components/govuk/field/inputs.rb
ccs-frontend_helpers-0.1.1 lib/ccs/components/govuk/field/inputs.rb
ccs-frontend_helpers-0.1.1.rc.1 lib/ccs/components/govuk/field/inputs.rb
ccs-frontend_helpers-0.1.0.rc.7 lib/ccs/components/govuk/field/inputs.rb
ccs-frontend_helpers-0.1.0.rc.6 lib/ccs/components/govuk/field/inputs.rb
ccs-frontend_helpers-0.1.0.rc.5 lib/ccs/components/govuk/field/inputs.rb
ccs-frontend_helpers-0.1.0.rc.4 lib/ccs/components/govuk/field/inputs.rb
ccs-frontend_helpers-0.1.0.rc.3 lib/ccs/components/govuk/field/inputs.rb