Sha256: 388b4246b20ed4a392e53b12cf5b71744e529ce2e6b12ad274a48b7fea9b0ec6

Contents?: true

Size: 1.57 KB

Versions: 4

Compression:

Stored size: 1.57 KB

Contents

(function($) {
    $.fn.bootstrapValidator.i18n.callback = $.extend($.fn.bootstrapValidator.i18n.callback || {}, {
        'default': 'Please enter a valid value'
    });

    $.fn.bootstrapValidator.validators.callback = {
        html5Attributes: {
            message: 'message',
            callback: 'callback'
        },

        /**
         * Return result from the callback method
         *
         * @param {BootstrapValidator} validator The validator plugin instance
         * @param {jQuery} $field Field element
         * @param {Object} options Can consist of the following keys:
         * - callback: The callback method that passes 2 parameters:
         *      callback: function(fieldValue, validator, $field) {
         *          // fieldValue is the value of field
         *          // validator is instance of BootstrapValidator
         *          // $field is the field element
         *      }
         * - message: The invalid message
         * @returns {Boolean|Deferred}
         */
        validate: function(validator, $field, options) {
            var value = $field.val();

            if (options.callback) {
                var dfd      = new $.Deferred(),
                    response = $.fn.bootstrapValidator.helpers.call(options.callback, [value, validator, $field]);
                dfd.resolve($field, 'callback', 'boolean' === typeof response ? response : response.valid, 'object' === typeof response && response.message ? response.message : null);
                return dfd;
            }

            return true;
        }
    };
}(window.jQuery));

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
bootstrap_validator_rails-0.1.0 vendor/assets/javascripts/validator/callback.js
bootstrap_validator_rails-0.0.6 vendor/assets/javascripts/validator/callback.js
bootstrap_validator_rails-0.0.5 vendor/assets/javascripts/validator/callback.js
bootstrap_validator-rails-0.0.1 vendor/javascripts/validator/callback.js