Sha256: 64d02b5f3f36407f4c7b48b65078aa92d29d14d94a27dc6136a05409bc5c929d

Contents?: true

Size: 864 Bytes

Versions: 7

Compression:

Stored size: 864 Bytes

Contents

module SimpleForm
  module Components
    # Needs to be enabled in order to do automatic lookups.
    module Maxlength
      def maxlength
        input_html_options[:maxlength] ||= maximum_length_from_validation || limit
        nil
      end

      private

      def maximum_length_from_validation
        maxlength = options[:maxlength]
        if maxlength.is_a?(String) || maxlength.is_a?(Integer)
          maxlength
        else
          length_validator = find_length_validator

          if length_validator && !has_tokenizer?(length_validator)
            length_validator.options[:is] || length_validator.options[:maximum]
          end
        end
      end

      def find_length_validator
        find_validator(:length)
      end

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

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
simple_form-3.0.4 lib/simple_form/components/maxlength.rb
simple_form-3.0.3 lib/simple_form/components/maxlength.rb
simple_form-3.0.2 lib/simple_form/components/maxlength.rb
simple_form-3.0.1 lib/simple_form/components/maxlength.rb
simple_form-3.0.0 lib/simple_form/components/maxlength.rb
simple_form-3.0.0.rc lib/simple_form/components/maxlength.rb
simple_form-3.0.0.beta1 lib/simple_form/components/maxlength.rb