浏览代码

#31: The ```remote``` validator supports dynamic data

nghuuphuoc 11 年之前
父节点
当前提交
3e2f176872
共有 5 个文件被更改,包括 32 次插入5 次删除
  1. 1 0
      CHANGELOG.md
  2. 22 4
      README.md
  3. 4 0
      dist/js/bootstrapValidator.js
  4. 1 1
      dist/js/bootstrapValidator.min.js
  5. 4 0
      src/js/validator/remote.js

+ 1 - 0
CHANGELOG.md

@@ -6,6 +6,7 @@ __New features__:
 
 * [#44: Rewrite entirely using Deferred](https://github.com/nghuuphuoc/bootstrapvalidator/issues/44)
 * #26, #27, #67: Add choice validator
+* [#31: The ```remote``` validator supports dynamic data](https://github.com/nghuuphuoc/bootstrapvalidator/issues/31)
 * [#36, #58: Add method to validate form manually](https://github.com/nghuuphuoc/bootstrapvalidator/issues/58)
 * [#41: Disable submit button on successful form submit](https://github.com/nghuuphuoc/bootstrapvalidator/issues/41)
 * [#42: Add submit button to ```submitHandler()``` parameter](https://github.com/nghuuphuoc/bootstrapvalidator/issues/42)

+ 22 - 4
README.md

@@ -271,10 +271,28 @@ regexp (*)  | n/a     | The Javascript regular expression
 
 ### Remote Validator
 
-Option name | Default | Description
-------------|---------|------------
-message     | n/a     | The error message
-url (*)     | n/a     | The remote URL that responses an encoded JSON of array containing the ```valid``` key
+Option name | Default                        | Description
+------------|--------------------------------|------------
+message     | n/a                            | The error message
+url (*)     | n/a                            | The remote URL that responses an encoded JSON of array containing the ```valid``` key
+data        | ```{ fieldName: fieldValue}``` | The data sent to remote URL
+
+It also supports dynamic data which is returned by a function:
+
+```
+remote: {
+    url: 'remote.php',
+    data: function(validator) {
+        // validator is the plugin instance
+
+        // Returns an object which is used to send to remote URL
+        // For example, the sample code below posts the username to remote URL:
+        //  return {
+        //      username: validator.getFieldElements('username').val()
+        //  }
+    }
+}
+```
 
 ### StringLength Validator
 

+ 4 - 0
dist/js/bootstrapValidator.js

@@ -868,6 +868,10 @@
             if (data == null) {
                 data = {};
             }
+            // Support dynamic data
+            if ('function' == typeof data) {
+                data = data.call(this, validator);
+            }
             data[name] = value;
 
             var dfd = new $.Deferred();

文件差异内容过多而无法显示
+ 1 - 1
dist/js/bootstrapValidator.min.js


+ 4 - 0
src/js/validator/remote.js

@@ -24,6 +24,10 @@
             if (data == null) {
                 data = {};
             }
+            // Support dynamic data
+            if ('function' == typeof data) {
+                data = data.call(this, validator);
+            }
             data[name] = value;
 
             var dfd = new $.Deferred();