Sha256: 19156e49d17e2ba0461b4cb484876ba498563cdcd46c622a64e35c92b39217bc

Contents?: true

Size: 571 Bytes

Versions: 1

Compression:

Stored size: 571 Bytes

Contents

module GOVUKDesignSystemFormBuilder
  module Elements
    class ErrorMessage < Base
      using PrefixableArray

      include Traits::Error

      def html
        return unless has_errors?

        tag.span(class: %(#{brand}-error-message), id: error_id) do
          safe_join([hidden_prefix, message])
        end
      end

    private

      def hidden_prefix
        tag.span('Error: ', class: %(#{brand}-visually-hidden))
      end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
govuk_design_system_formbuilder-2.8.0 lib/govuk_design_system_formbuilder/elements/error_message.rb