nghuuphuoc 11 年 前
コミット
c30f7f808a

+ 2 - 0
CHANGELOG.md

@@ -4,6 +4,8 @@
 
 * [#168](https://github.com/nghuuphuoc/bootstrapvalidator/pull/168): Add siren and siret validators, thanks to [@jswale](https://github.com/jswale)
 * [#171](https://github.com/nghuuphuoc/bootstrapvalidator/pull/171): The [```phone``` validator](http://bootstrapvalidator.com/validators/phone/) now supports +1 country code and area code for US phone number, thanks to [@tomByrer](https://github.com/tomByrer)
+* [#173](https://github.com/nghuuphuoc/bootstrapvalidator/pull/173): The [```remote``` validator](http://bootstrapvalidator.com/validators/remote/) allows to override ```name``` option, thanks to [@jswale](https://github.com/jswale)
+* [#178](https://github.com/nghuuphuoc/bootstrapvalidator/pull/178): Do not validate fields that ```enabled``` is set to ```false```, thanks to [@henningda](https://github.com/henningda)
 
 ## v0.4.1 (2014-04-12)
 

+ 1 - 0
README.md

@@ -85,6 +85,7 @@ Big thanks to the contributors:
 * [@gercheq](https://github.com/gercheq)
 * [@khangvm53](https://github.com/khangvm53)
 * [@kristian-puccio](https://github.com/kristian-puccio)
+* [@henningda](https://github.com/henningda)
 * [@ikanedo](https://github.com/ikanedo)
 * [@iplus](https://github.com/iplus)
 * [@jswale](https://github.com/jswale)

+ 8 - 6
dist/js/bootstrapValidator.js

@@ -454,7 +454,7 @@
                 validateResult;
 
             // We don't need to validate disabled, hidden field
-            if ($field.is(':disabled') || $field.is(':hidden') || !$field.is(':visible')) {
+            if ($field.is(':disabled') || $field.is(':hidden') || !$field.is(':visible') || !this.options.fields[field]['enabled']) {
                 return this;
             }
 
@@ -1846,11 +1846,12 @@
         }
     };
 }(window.jQuery));
-;(function($) {
+;(function ($) {
     $.fn.bootstrapValidator.validators.remote = {
         html5Attributes: {
             message: 'message',
-            url: 'url'
+            url: 'url',
+            name: 'name'
         },
 
         /**
@@ -1864,6 +1865,7 @@
          *  {
          *      <fieldName>: <fieldValue>
          *  }
+         * - name [optional]: Override the field name for the request.
          * - message: The invalid message
          * @returns {Boolean|Deferred}
          */
@@ -1881,7 +1883,7 @@
             if ('function' == typeof data) {
                 data = data.call(this, validator);
             }
-            data[name] = value;
+            data[options.name || name] = value;
 
             var dfd = new $.Deferred();
             var xhr = $.ajax({
@@ -1913,7 +1915,7 @@
          * - message: The invalid message
 		 * @returns {Boolean}
 		 */
-		validate : function(validator, $field, options) {
+		validate: function(validator, $field, options) {
 			var value = $field.val();
 			if (value == '') {
 				return true;
@@ -1947,7 +1949,7 @@
          * - message: The invalid message
          * @returns {Boolean}
          */
-		validate : function(validator, $field, options) {
+		validate: function(validator, $field, options) {
 			var value = $field.val();
 			if (value == '') {
 				return true;

ファイルの差分が大きいため隠しています
+ 1 - 1
dist/js/bootstrapValidator.min.js


+ 1 - 1
src/js/bootstrapValidator.js

@@ -453,7 +453,7 @@
                 validateResult;
 
             // We don't need to validate disabled, hidden field
-            if ($field.is(':disabled') || $field.is(':hidden') || !$field.is(':visible') || !this.options.fields[field].enabled) {
+            if ($field.is(':disabled') || $field.is(':hidden') || !$field.is(':visible') || !this.options.fields[field]['enabled']) {
                 return this;
             }
 

+ 52 - 52
src/js/validator/remote.js

@@ -1,58 +1,58 @@
-(function($) {
-		$.fn.bootstrapValidator.validators.remote = {
-				html5Attributes: {
-						message: 'message',
-						url: 'url',
-						name : 'name'
-				},
+(function ($) {
+    $.fn.bootstrapValidator.validators.remote = {
+        html5Attributes: {
+            message: 'message',
+            url: 'url',
+            name: 'name'
+        },
 
-				/**
-				 * Request a remote server to check the input value
-				 *
-				 * @param {BootstrapValidator} validator Plugin instance
-				 * @param {jQuery} $field Field element
-				 * @param {Object} options Can consist of the following keys:
-				 * - url
-				 * - data [optional]: By default, it will take the value
-				 *  {
-				 *      <fieldName>: <fieldValue>
-				 *  }
-				 * - name [optional]: Override the field name for the request.
-				 * - message: The invalid message
-				 * @returns {Boolean|Deferred}
-				 */
-				validate: function(validator, $field, options) {
-						var value = $field.val();
-						if (value == '') {
-								return true;
-						}
+        /**
+         * Request a remote server to check the input value
+         *
+         * @param {BootstrapValidator} validator Plugin instance
+         * @param {jQuery} $field Field element
+         * @param {Object} options Can consist of the following keys:
+         * - url
+         * - data [optional]: By default, it will take the value
+         *  {
+         *      <fieldName>: <fieldValue>
+         *  }
+         * - name [optional]: Override the field name for the request.
+         * - message: The invalid message
+         * @returns {Boolean|Deferred}
+         */
+        validate: function(validator, $field, options) {
+            var value = $field.val();
+            if (value == '') {
+                return true;
+            }
 
-						var name = $field.attr('data-bv-field'), data = options.data;
-						if (data == null) {
-								data = {};
-						}
-						// Support dynamic data
-						if ('function' == typeof data) {
-								data = data.call(this, validator);
-						}
-						data[options.name || name] = value;
+            var name = $field.attr('data-bv-field'), data = options.data;
+            if (data == null) {
+                data = {};
+            }
+            // Support dynamic data
+            if ('function' == typeof data) {
+                data = data.call(this, validator);
+            }
+            data[options.name || name] = value;
 
-						var dfd = new $.Deferred();
-						var xhr = $.ajax({
-								type: 'POST',
-								url: options.url,
-								dataType: 'json',
-								data: data
-						});
-						xhr.then(function(response) {
-								dfd.resolve($field, 'remote', response.valid === true || response.valid === 'true');
-						});
+            var dfd = new $.Deferred();
+            var xhr = $.ajax({
+                type: 'POST',
+                url: options.url,
+                dataType: 'json',
+                data: data
+            });
+            xhr.then(function(response) {
+                dfd.resolve($field, 'remote', response.valid === true || response.valid === 'true');
+            });
 
-						dfd.fail(function() {
-								xhr.abort();
-						});
+            dfd.fail(function() {
+                xhr.abort();
+            });
 
-						return dfd;
-				}
-		};
+            return dfd;
+        }
+    };
 }(window.jQuery));

+ 1 - 1
src/js/validator/siren.js

@@ -9,7 +9,7 @@
          * - message: The invalid message
 		 * @returns {Boolean}
 		 */
-		validate : function(validator, $field, options) {
+		validate: function(validator, $field, options) {
 			var value = $field.val();
 			if (value == '') {
 				return true;

+ 1 - 1
src/js/validator/siret.js

@@ -9,7 +9,7 @@
          * - message: The invalid message
          * @returns {Boolean}
          */
-		validate : function(validator, $field, options) {
+		validate: function(validator, $field, options) {
 			var value = $field.val();
 			if (value == '') {
 				return true;