Sha256: e87aae4a2e00a1e7499fee54c4ab903cdb9c61dd210dd633d5de27330b8bcd38

Contents?: true

Size: 747 Bytes

Versions: 16

Compression:

Stored size: 747 Bytes

Contents

module Formstrap
  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

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
formstrap-0.4.5 app/models/concerns/formstrap/validatable.rb
formstrap-0.4.4 app/models/concerns/formstrap/validatable.rb
formstrap-0.4.3 app/models/concerns/formstrap/validatable.rb
formstrap-0.4.2 app/models/concerns/formstrap/validatable.rb
formstrap-0.3.5 app/models/concerns/formstrap/validatable.rb
formstrap-0.3.4 app/models/concerns/formstrap/validatable.rb
formstrap-0.3.3 app/models/concerns/formstrap/validatable.rb
formstrap-0.3.2 app/models/concerns/formstrap/validatable.rb
formstrap-0.3.1 app/models/concerns/formstrap/validatable.rb
formstrap-0.3.0 app/models/concerns/formstrap/validatable.rb
formstrap-0.2.1 app/models/concerns/formstrap/validatable.rb
formstrap-0.2.0 app/models/concerns/formstrap/validatable.rb
formstrap-0.1.3 app/models/concerns/formstrap/validatable.rb
formstrap-0.1.2 app/models/concerns/formstrap/validatable.rb
formstrap-0.1.1 app/models/concerns/formstrap/validatable.rb
formstrap-0.1.0 app/models/concerns/formstrap/validatable.rb