Sha256: c5be859a01ec82467b4e327d093b1f1c65ee707b0b9edf9b6671d40b4ac72ab9

Contents?: true

Size: 983 Bytes

Versions: 7

Compression:

Stored size: 983 Bytes

Contents

# frozen_string_literal: true
module SimpleForm
  module Components
    # Needs to be enabled in order to do automatic lookups.
    module Minlength
      def minlength(wrapper_options = nil)
        input_html_options[:minlength] ||= minimum_length_from_validation
        nil
      end

      private

      def minimum_length_from_validation
        minlength = options[:minlength]
        if minlength.is_a?(String) || minlength.is_a?(Integer)
          minlength
        else
          length_validator = find_length_validator
          minimum_length_value_from(length_validator)
        end
      end

      def find_length_validator
        find_validator(:length)
      end

      def has_tokenizer?(length_validator)
        length_validator.options[:tokenizer]
      end

      def minimum_length_value_from(length_validator)
        if length_validator
          length_validator.options[:is] || length_validator.options[:minimum]
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
simple_form-5.0.3 lib/simple_form/components/minlength.rb
simple_form-5.0.2 lib/simple_form/components/minlength.rb
simple_form-5.0.1 lib/simple_form/components/minlength.rb
simple_form-5.0.0 lib/simple_form/components/minlength.rb
simple_form-4.1.0 lib/simple_form/components/minlength.rb
simple_form-4.0.1 lib/simple_form/components/minlength.rb
simple_form-4.0.0 lib/simple_form/components/minlength.rb