Sha256: e8f10a6127028e58c8c4da1c55d938c6c37664a3faa6abfcaab81fd0161b0112

Contents?: true

Size: 662 Bytes

Versions: 39

Compression:

Stored size: 662 Bytes

Contents

module Avo
  module Fields
    module Concerns
      module IsRequired
        extend ActiveSupport::Concern

        def is_required?
          return required_from_validators if required.nil?

          Avo::ExecutionContext.new(target: required, record: record, view: view, resource: resource).handle
        end

        private

        def required_from_validators
          return false unless record.present?

          validators.any? do |validator|
            validator.is_a? ActiveModel::Validations::PresenceValidator
          end
        end

        def validators
          record.class.validators_on(id)
        end
      end
    end
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
avo-3.16.4 lib/avo/fields/concerns/is_required.rb
avo-3.16.3 lib/avo/fields/concerns/is_required.rb
avo-3.16.2 lib/avo/fields/concerns/is_required.rb
avo-3.16.1 lib/avo/fields/concerns/is_required.rb
avo-3.16.0 lib/avo/fields/concerns/is_required.rb
avo-3.15.7 lib/avo/fields/concerns/is_required.rb
avo-3.15.6 lib/avo/fields/concerns/is_required.rb
avo-3.15.5 lib/avo/fields/concerns/is_required.rb
avo-3.15.4 lib/avo/fields/concerns/is_required.rb
avo-3.15.3 lib/avo/fields/concerns/is_required.rb
avo-3.15.2 lib/avo/fields/concerns/is_required.rb
avo-3.15.1 lib/avo/fields/concerns/is_required.rb
avo-3.15.0 lib/avo/fields/concerns/is_required.rb
avo-3.14.5 lib/avo/fields/concerns/is_required.rb
avo-3.14.4 lib/avo/fields/concerns/is_required.rb
avo-3.14.3 lib/avo/fields/concerns/is_required.rb
avo-3.14.2 lib/avo/fields/concerns/is_required.rb
avo-3.14.1 lib/avo/fields/concerns/is_required.rb
avo-3.14.0 lib/avo/fields/concerns/is_required.rb
avo-3.13.7 lib/avo/fields/concerns/is_required.rb