Sha256: 30bb17c239fd435e829d09658e023758fea574cb5a565a23bee56a1a623c4cdb

Contents?: true

Size: 763 Bytes

Versions: 6

Compression:

Stored size: 763 Bytes

Contents

module GOVUKDesignSystemFormBuilder
  module Elements
    class ErrorMessage < GOVUKDesignSystemFormBuilder::Base
      def initialize(builder, object_name, attribute_name, options = {})
        super(builder, object_name, attribute_name)
        @options = default_options.merge(options)
      end

      def html
        return nil unless has_errors?

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

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

    private

      def default_options
        {}
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
govuk_design_system_formbuilder-0.7.5 lib/govuk_design_system_formbuilder/elements/error_message.rb
govuk_design_system_formbuilder-0.7.4 lib/govuk_design_system_formbuilder/elements/error_message.rb
govuk_design_system_formbuilder-0.7.3 lib/govuk_design_system_formbuilder/elements/error_message.rb
govuk_design_system_formbuilder-0.7.2 lib/govuk_design_system_formbuilder/elements/error_message.rb
govuk_design_system_formbuilder-0.7.1 lib/govuk_design_system_formbuilder/elements/error_message.rb
govuk_design_system_formbuilder-0.7.0 lib/govuk_design_system_formbuilder/elements/error_message.rb