From 1e2425bcaa9f216143741ce78587ecbf3abdd51e Mon Sep 17 00:00:00 2001 From: Alexandre Alouit Date: Sun, 12 Jul 2015 20:01:55 +0200 Subject: [PATCH 1/2] Non type:submit input/button Add trigger for non type:submit input/button --- dist/validator.js | 6 +++--- dist/validator.min.js | 2 +- js/validator.js | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/dist/validator.js b/dist/validator.js index 58d414c..030b00d 100644 --- a/dist/validator.js +++ b/dist/validator.js @@ -214,9 +214,9 @@ Validator.prototype.toggleSubmit = function () { if(!this.options.disable) return - var $btn = $('button[type="submit"], input[type="submit"]') + var $btn = $('button[type="submit"], [data-validator="submit"], input[type="submit"]') .filter('[form="' + this.$element.attr('id') + '"]') - .add(this.$element.find('input[type="submit"], button[type="submit"]')) + .add(this.$element.find('input[type="submit"], button[type="submit"], [data-validator="submit"]')) $btn.toggleClass('disabled', this.isIncomplete() || this.hasErrors()) .css({'pointer-events': 'all', 'cursor': 'pointer'}) } @@ -252,7 +252,7 @@ .html(originalContent) }) - this.$element.find('input[type="submit"], button[type="submit"]').removeClass('disabled') + this.$element.find('input[type="submit"], button[type="submit"], [data-validator="submit"]').removeClass('disabled') this.$element.find('.has-error').removeClass('has-error') diff --git a/dist/validator.min.js b/dist/validator.min.js index ffb4315..b42c8f8 100644 --- a/dist/validator.min.js +++ b/dist/validator.min.js @@ -6,4 +6,4 @@ * https://github.com/1000hz/bootstrap-validator */ -+function(a){"use strict";function b(b){return this.each(function(){var c=a(this),e=a.extend({},d.DEFAULTS,c.data(),"object"==typeof b&&b),f=c.data("bs.validator");(f||"destroy"!=b)&&(f||c.data("bs.validator",f=new d(this,e)),"string"==typeof b&&f[b]())})}var c=':input:not([type="submit"], button):enabled:visible',d=function(b,c){this.$element=a(b),this.options=c,c.errors=a.extend({},d.DEFAULTS.errors,c.errors);for(var e in c.custom)if(!c.errors[e])throw new Error("Missing default error message for custom validator: "+e);a.extend(d.VALIDATORS,c.custom),this.$element.attr("novalidate",!0),this.toggleSubmit(),this.$element.on("input.bs.validator change.bs.validator focusout.bs.validator",a.proxy(this.validateInput,this)),this.$element.on("submit.bs.validator",a.proxy(this.onSubmit,this)),this.$element.find("[data-match]").each(function(){var b=a(this),c=b.data("match");a(c).on("input.bs.validator",function(){b.val()&&b.trigger("input.bs.validator")})})};d.DEFAULTS={delay:500,html:!1,disable:!0,custom:{},errors:{match:"Does not match",minlength:"Not long enough"},feedback:{success:"glyphicon-ok",error:"glyphicon-warning-sign"}},d.VALIDATORS={"native":function(a){var b=a[0];return b.checkValidity?b.checkValidity():!0},match:function(b){var c=b.data("match");return!b.val()||b.val()===a(c).val()},minlength:function(a){var b=a.data("minlength");return!a.val()||a.val().length>=b}},d.prototype.validateInput=function(b){var c=a(b.target),d=c.data("bs.validator.errors");if(c.is('[type="radio"]')&&(c=this.$element.find('input[name="'+c.attr("name")+'"]')),this.$element.trigger(b=a.Event("validate.bs.validator",{relatedTarget:c[0]})),!b.isDefaultPrevented()){var e=this;this.runValidators(c).done(function(f){c.data("bs.validator.errors",f),f.length?e.showErrors(c):e.clearErrors(c),d&&f.toString()===d.toString()||(b=f.length?a.Event("invalid.bs.validator",{relatedTarget:c[0],detail:f}):a.Event("valid.bs.validator",{relatedTarget:c[0],detail:d}),e.$element.trigger(b)),e.toggleSubmit(),e.$element.trigger(a.Event("validated.bs.validator",{relatedTarget:c[0]}))})}},d.prototype.runValidators=function(b){function c(a){return b.data(a+"-error")||b.data("error")||"native"==a&&b[0].validationMessage||g.errors[a]}var e=[],f=a.Deferred(),g=this.options;return b.data("bs.validator.deferred")&&b.data("bs.validator.deferred").reject(),b.data("bs.validator.deferred",f),a.each(d.VALIDATORS,a.proxy(function(a,d){if((b.data(a)||"native"==a)&&!d.call(this,b)){var f=c(a);!~e.indexOf(f)&&e.push(f)}},this)),!e.length&&b.val()&&b.data("remote")?this.defer(b,function(){var d={};d[b.attr("name")]=b.val(),a.get(b.data("remote"),d).fail(function(a,b,d){e.push(c("remote")||d)}).always(function(){f.resolve(e)})}):f.resolve(e),f.promise()},d.prototype.validate=function(){var a=this.options.delay;return this.options.delay=0,this.$element.find(c).trigger("input.bs.validator"),this.options.delay=a,this},d.prototype.showErrors=function(b){var c=this.options.html?"html":"text";this.defer(b,function(){var d=b.closest(".form-group"),e=d.find(".help-block.with-errors"),f=d.find(".form-control-feedback"),g=b.data("bs.validator.errors");g.length&&(g=a("