Sha256: e8f10a6127028e58c8c4da1c55d938c6c37664a3faa6abfcaab81fd0161b0112

Contents?: true

Size: 662 Bytes

Versions: 24

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

24 entries across 24 versions & 1 rubygems

Version Path
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
avo-3.13.6 lib/avo/fields/concerns/is_required.rb
avo-3.13.5 lib/avo/fields/concerns/is_required.rb
avo-3.13.4 lib/avo/fields/concerns/is_required.rb
avo-3.13.3 lib/avo/fields/concerns/is_required.rb
avo-3.13.2 lib/avo/fields/concerns/is_required.rb
avo-3.13.1 lib/avo/fields/concerns/is_required.rb
avo-3.13.0 lib/avo/fields/concerns/is_required.rb
avo-3.12.0 lib/avo/fields/concerns/is_required.rb
avo-3.11.10 lib/avo/fields/concerns/is_required.rb
avo-3.11.9 lib/avo/fields/concerns/is_required.rb
avo-3.11.8 lib/avo/fields/concerns/is_required.rb
avo-3.11.7 lib/avo/fields/concerns/is_required.rb
avo-3.11.6 lib/avo/fields/concerns/is_required.rb
avo-3.11.5 lib/avo/fields/concerns/is_required.rb
avo-3.11.4 lib/avo/fields/concerns/is_required.rb