Sha256: aa28235f978878e5c97afe07ebf47209d4f85cbdf36285863ed1d02e00822eb4

Contents?: true

Size: 1002 Bytes

Versions: 11

Compression:

Stored size: 1002 Bytes

Contents

# frozen_string_literal: true
module SimpleForm
  module Components
    module HTML5
      def initialize(*)
        @html5 = false
      end

      def html5(wrapper_options = nil)
        @html5 = true

        input_html_options[:required]        = input_html_required_option
        input_html_options[:'aria-required'] = input_html_aria_required_option

        input_html_options[:'aria-invalid']  = has_errors? || nil

        nil
      end

      def html5?
        @html5
      end

      def input_html_required_option
        !options[:required].nil? ? required_field? : has_required?
      end

      def input_html_aria_required_option
        !options[:required].nil? ? (required_field? || nil) : (has_required? || nil)
      end

      def has_required?
        # We need to check browser_validations because
        # some browsers are still checking required even
        # if novalidate was given.
        required_field? && SimpleForm.browser_validations
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
simple_form-5.3.0 lib/simple_form/components/html5.rb
simple_form-5.2.0 lib/simple_form/components/html5.rb
simple_form-5.1.0 lib/simple_form/components/html5.rb
simple_form-5.0.3 lib/simple_form/components/html5.rb
simple_form-5.0.2 lib/simple_form/components/html5.rb
simple_form-5.0.1 lib/simple_form/components/html5.rb
simple_form-5.0.0 lib/simple_form/components/html5.rb
simple_form-4.1.0 lib/simple_form/components/html5.rb
simple_form-4.0.1 lib/simple_form/components/html5.rb
simple_form-4.0.0 lib/simple_form/components/html5.rb
simple_form-3.5.1 lib/simple_form/components/html5.rb