Sha256: 4723db1195afabf3453b021cb824e5492a1463ab2b18c30bce0d5c1fce9aaecc

Contents?: true

Size: 745 Bytes

Versions: 1

Compression:

Stored size: 745 Bytes

Contents

module SimpleForm
  module Helpers
    module Required
      private

      def required_field?
        @required
      end

      def calculate_required
        if !options[:required].nil?
          options[:required]
        elsif has_validators?
          (attribute_validators + reflection_validators).any? do |v|
            v.kind == :presence && valid_validator?(v)
          end
        else
          required_by_default?
        end
      end

      def required_by_default?
        SimpleForm.required_by_default
      end

      # Do not use has_required? because we want to add the class
      # regardless of the required option.
      def required_class
        required_field? ? :required : :optional
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
simple_form-2.0.0.rc lib/simple_form/helpers/required.rb