Sha256: deb4e4c9b471dc7ed5c7e61784e8d2cafa55cd241a939bf5892dc21cdeb1f5e7

Contents?: true

Size: 648 Bytes

Versions: 3

Compression:

Stored size: 648 Bytes

Contents

module GOVUKDesignSystemFormBuilder
  module Elements
    class ErrorMessage < GOVUKDesignSystemFormBuilder::Base
      def initialize(builder, object_name, attribute_name)
        super(builder, object_name, attribute_name)
      end

      def html
        return nil unless has_errors?

        content_tag('span', class: 'govuk-error-message', id: error_id) do
          safe_join(
            [
              tag.span('Error: ', class: 'govuk-visually-hidden'),
              message
            ]
          )
        end
      end

      def message
        @builder.object.errors.messages[@attribute_name]&.first
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
govuk_design_system_formbuilder-1.0.1 lib/govuk_design_system_formbuilder/elements/error_message.rb
govuk_design_system_formbuilder-1.0.0 lib/govuk_design_system_formbuilder/elements/error_message.rb
govuk_design_system_formbuilder-0.9.8 lib/govuk_design_system_formbuilder/elements/error_message.rb