Sha256: 39fd8561500b263f0c982c5beef9dd4482dc61968530605ad7e4b67bc105244e

Contents?: true

Size: 823 Bytes

Versions: 17

Compression:

Stored size: 823 Bytes

Contents

module Headmin
  module Form
    module Validatable
      extend ActiveSupport::Concern

      included do
        def validation_options
          {
            id: validation_id,
            message: validation_message,
            valid: valid?
          }
        end

        def validate?
          form.object&.errors&.any?
        end

        private

        def valid?
          !form.object&.errors&.has_key?(attribute)
        end

        def validation_message
          form.object&.errors&.full_messages_for(attribute)&.join(", ")
        end

        def validation_id
          [attribute.to_s, "validation"].join("_").parameterize.underscore
        end

        def validation_class
          return unless validate?
          valid? ? "is-valid" : "is-invalid"
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
headmin-0.6.3 app/models/concerns/headmin/form/validatable.rb
headmin-0.6.2 app/models/concerns/headmin/form/validatable.rb
headmin-0.6.1 app/models/concerns/headmin/form/validatable.rb
headmin-0.6.0 app/models/concerns/headmin/form/validatable.rb
headmin-0.5.9 app/models/concerns/headmin/form/validatable.rb
headmin-0.5.8 app/models/concerns/headmin/form/validatable.rb
headmin-0.5.7 app/models/concerns/headmin/form/validatable.rb
headmin-0.5.6 app/models/concerns/headmin/form/validatable.rb
headmin-0.5.5 app/models/concerns/headmin/form/validatable.rb
headmin-0.5.4 app/models/concerns/headmin/form/validatable.rb
headmin-0.5.3 app/models/concerns/headmin/form/validatable.rb
headmin-0.5.2 app/models/concerns/headmin/form/validatable.rb
headmin-0.5.1 app/models/concerns/headmin/form/validatable.rb
headmin-0.5.0 app/models/concerns/headmin/form/validatable.rb
headmin-0.4.2 app/models/concerns/headmin/form/validatable.rb
headmin-0.4.1 app/models/concerns/headmin/form/validatable.rb
headmin-0.4.0 app/models/concerns/headmin/form/validatable.rb