浏览代码

Update changes after merging from 0.3

nghuuphuoc 11 年之前
父节点
当前提交
f5de5a6c15
共有 3 个文件被更改,包括 40 次插入10 次删除
  1. 19 8
      README.md
  2. 2 2
      demo/validators.html
  3. 19 0
      dist/js/bootstrapValidator.js

+ 19 - 8
README.md

@@ -294,21 +294,32 @@ $(form).bootstrapValidator({
 });
 });
 ```
 ```
 
 
+For Rails, the input field is constructed from model name and field name. For Example, User have email as field, when form helper render
+view, the input field name will be 'user[email]'. The syntax for these is somewhat different as shown below:
+
+```javascript
+$(form).bootstrapValidator({
+    fields: {
+        'user[email]': {
+            // Replace <validatorName> with the name of validator
+            // <validatorOptions> will be passed as third parameter of the
+            // validate(validator, $field, options) method
+            <validatorName>: <validatorOptions>
+        }
+    }
+});
+```
+
 To see how built-in validators are developed, you can look at their sources located at the [```src/js/validator```](src/js/validator) directory.
 To see how built-in validators are developed, you can look at their sources located at the [```src/js/validator```](src/js/validator) directory.
 
 
 ## Build
 ## Build
 
 
 BootstrapValidator uses [grunt](http://gruntjs.com) to simplify building process.
 BootstrapValidator uses [grunt](http://gruntjs.com) to simplify building process.
 
 
-From the BootstrapValidator root directory, execute the following commands to install the dependent packages (the administrator permission might be required):
+From the BootstrapValidator root directory, install dependencies:
 
 
 ```bash
 ```bash
-$ npm install grunt --save-dev
-$ npm install grunt-contrib-concat --save-dev
-$ npm install grunt-contrib-copy --save-dev
-$ npm install grunt-contrib-cssmin --save-dev
-$ npm install grunt-contrib-uglify --save-dev
-$ npm install grunt-contrib-watch --save-dev
+$ npm install
 ```
 ```
 
 
 Then, uses grunt to build:
 Then, uses grunt to build:
@@ -368,4 +379,4 @@ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-```
+```

+ 2 - 2
demo/validators.html

@@ -90,7 +90,7 @@
                             <div class="form-group">
                             <div class="form-group">
                                 <label class="col-lg-3 control-label">US zip code</label>
                                 <label class="col-lg-3 control-label">US zip code</label>
                                 <div class="col-lg-3">
                                 <div class="col-lg-3">
-                                    <input type="text" class="form-control" name="zipCode" />
+                                    <input type="text" class="form-control" name="usZipCode" />
                                 </div>
                                 </div>
                             </div>
                             </div>
                         </fieldset>
                         </fieldset>
@@ -203,7 +203,7 @@ $(document).ready(function() {
                     }
                     }
                 }
                 }
             },
             },
-            zipCode: {
+            usZipCode: {
                 validators: {
                 validators: {
                     zipCode: {
                     zipCode: {
                         country: 'US',
                         country: 'US',

+ 19 - 0
dist/js/bootstrapValidator.js

@@ -616,6 +616,25 @@
     }
     }
 }(window.jQuery));
 }(window.jQuery));
 ;(function($) {
 ;(function($) {
+    $.fn.bootstrapValidator.validators.dkZipCode = {
+        /**
+         * Return true if and only if the input value is a valid DK zip code
+         *
+         * @param {BootstrapValidator} validator The validator plugin instance
+         * @param {jQuery} $field Field element
+         * @param {Object} options
+         * @returns {Boolean}
+         */
+        validate: function(validateInstance, $field, options) {
+            var value = $field.val();
+            if (value == '') {
+                return true;
+            }
+            return /^(DK(-|\s)?)?\d{4}$/i.test(value);
+        }
+    };
+}(window.jQuery));
+;(function($) {
     $.fn.bootstrapValidator.validators.emailAddress = {
     $.fn.bootstrapValidator.validators.emailAddress = {
         /**
         /**
          * Return true if and only if the input value is a valid email address
          * Return true if and only if the input value is a valid email address