Sha256: 40579475c31021b0e2d32b6891322a312a117f7b4fd3c5081028bf5f11f1e94d

Contents?: true

Size: 827 Bytes

Versions: 11

Compression:

Stored size: 827 Bytes

Contents

# frozen_string_literal: true
module SimpleForm
  module Helpers
    module Required
      private

      def required_field?
        @required
      end

      def calculate_required
        if !options[:required].nil?
          options[:required]
        elsif has_validators?
          required_by_validators?
        else
          required_by_default?
        end
      end

      def required_by_validators?
        (attribute_validators + reflection_validators).any? { |v| v.kind == :presence && valid_validator?(v) }
      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

11 entries across 11 versions & 1 rubygems

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