浏览代码

#297: Disable feedback icons for particular fields

nghuuphuoc 11 年之前
父节点
当前提交
8e72a770ab
共有 5 个文件被更改,包括 197 次插入24 次删除
  1. 1 0
      CHANGELOG.md
  2. 166 0
      demo/feedbackIcons.html
  3. 14 11
      dist/js/bootstrapValidator.js
  4. 2 2
      dist/js/bootstrapValidator.min.js
  5. 14 11
      src/js/bootstrapValidator.js

+ 1 - 0
CHANGELOG.md

@@ -8,6 +8,7 @@
 * [#175](https://github.com/nghuuphuoc/bootstrapvalidator/issues/175): Showing errors in tooltip or popover
 * [#211](https://github.com/nghuuphuoc/bootstrapvalidator/issues/211), [#235](https://github.com/nghuuphuoc/bootstrapvalidator/issues/235): Add new method ```getInvalidFields()``` that returns all invalid fields
 * [#275](https://github.com/nghuuphuoc/bootstrapvalidator/issues/275): Add ```destroy()``` method
+* [#297](https://github.com/nghuuphuoc/bootstrapvalidator/issues/297): Disable feedback icons for particular fields
 * [#274](https://github.com/nghuuphuoc/bootstrapvalidator/pull/274): Fix feedback icons in ```input-group```, thanks to [@tiagofontella](https://github.com/tiagofontella)
 * [#282](https://github.com/nghuuphuoc/bootstrapvalidator/issues/282): Use error message that is returned from [```callback```](http://bootstrapvalidator.com/validators/callback/), [```remote```](http://bootstrapvalidator.com/validators/remote/) validators
 * [#287](https://github.com/nghuuphuoc/bootstrapvalidator/issues/287): Only send the submit button which is clicked. It's an enhancement for [#238](https://github.com/nghuuphuoc/bootstrapvalidator/issues/238)

+ 166 - 0
demo/feedbackIcons.html

@@ -0,0 +1,166 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <title>BootstrapValidator demo</title>
+
+    <link rel="stylesheet" href="../vendor/bootstrap/css/bootstrap.css"/>
+    <link rel="stylesheet" href="../dist/css/bootstrapValidator.css"/>
+    <script type="text/javascript" src="../vendor/jquery/jquery-1.10.2.min.js"></script>
+    <script type="text/javascript" src="../vendor/bootstrap/js/bootstrap.min.js"></script>
+    <script type="text/javascript" src="../dist/js/bootstrapValidator.js"></script>
+</head>
+<body>
+    <div class="container">
+        <div class="row">
+        <div class="col-lg-8 col-lg-offset-2">
+            <div class="page-header">
+                <h2>Disable feedback icons for particular fields</h2>
+            </div>
+
+            <form id="defaultForm" method="post" class="form-horizontal" action="target.php">
+                <div class="form-group">
+                    <label class="col-lg-3 control-label">Full name</label>
+                    <div class="col-lg-4">
+                        <input type="text" class="form-control" name="firstName" placeholder="First name" />
+                    </div>
+                    <div class="col-lg-4">
+                        <input type="text" class="form-control" name="lastName" placeholder="Last name" />
+                    </div>
+                </div>
+
+                <div class="form-group">
+                    <label class="col-lg-3 control-label">Username</label>
+                    <div class="col-lg-5">
+                        <input type="text" class="form-control" name="username" />
+                    </div>
+                </div>
+
+                <div class="form-group">
+                    <label class="col-lg-3 control-label">Email address</label>
+                    <div class="col-lg-5">
+                        <input type="text" class="form-control" name="email" data-bv-feedbackicons="false" />
+                    </div>
+                </div>
+
+                <div class="form-group">
+                    <label class="col-lg-3 control-label">Password</label>
+                    <div class="col-lg-5">
+                        <input type="password" class="form-control" name="password" />
+                    </div>
+                </div>
+
+                <div class="form-group">
+                    <label class="col-lg-3 control-label">Gender</label>
+                    <div class="col-lg-5">
+                        <div class="radio">
+                            <label>
+                                <input type="radio" name="gender" value="male" /> Male
+                            </label>
+                        </div>
+                        <div class="radio">
+                            <label>
+                                <input type="radio" name="gender" value="female" /> Female
+                            </label>
+                        </div>
+                        <div class="radio">
+                            <label>
+                                <input type="radio" name="gender" value="other" /> Other
+                            </label>
+                        </div>
+                    </div>
+                </div>
+
+                <div class="form-group hide">
+                    <div class="col-lg-9 col-lg-offset-3">
+                        <ul id="errors"></ul>
+                    </div>
+                </div>
+
+                <div class="form-group">
+                    <div class="col-lg-9 col-lg-offset-3">
+                        <button type="submit" class="btn btn-primary">Sign up</button>
+                    </div>
+                </div>
+            </form>
+        </div>
+    </div>
+
+<script type="text/javascript">
+$(document).ready(function() {
+    $('#defaultForm')
+        .bootstrapValidator({
+            message: 'This value is not valid',
+            feedbackIcons: {
+                valid: 'glyphicon glyphicon-ok',
+                invalid: 'glyphicon glyphicon-remove',
+                validating: 'glyphicon glyphicon-refresh'
+            },
+            fields: {
+                'firstName': {
+                    validators: {
+                        notEmpty: {
+                            message: 'The first name is required and cannot be empty'
+                        }
+                    }
+                },
+                'lastName': {
+                    validators: {
+                        notEmpty: {
+                            message: 'The last name is required and cannot be empty'
+                        }
+                    }
+                },
+                'username': {
+                    message: 'The username is not valid',
+                    validators: {
+                        notEmpty: {
+                            message: 'The username is required and cannot be empty'
+                        },
+                        stringLength: {
+                            min: 6,
+                            max: 30,
+                            message: 'The username must be more than 6 and less than 30 characters long'
+                        },
+                        regexp: {
+                            regexp: /^[a-zA-Z0-9_\.]+$/,
+                            message: 'The username can only consist of alphabetical, number, dot and underscore'
+                        },
+                        different: {
+                            field: 'password',
+                            message: 'The username and password cannot be the same as each other'
+                        }
+                    }
+                },
+                'email': {
+                    validators: {
+                        emailAddress: {
+                            message: 'The input is not a valid email address'
+                        }
+                    }
+                },
+                'password': {
+                    feedbackIcons: 'false',
+                    validators: {
+                        notEmpty: {
+                            message: 'The password is required and cannot be empty'
+                        },
+                        different: {
+                            field: 'username',
+                            message: 'The password cannot be the same as username'
+                        }
+                    }
+                },
+                'gender': {
+                    feedbackIcons: false,
+                    validators: {
+                        notEmpty: {
+                            message: 'The gender is required'
+                        }
+                    }
+                }
+            }
+        });
+});
+</script>
+</body>
+</html>

+ 14 - 11
dist/js/bootstrapValidator.js

@@ -223,16 +223,18 @@
                         }
 
                         var opts = {
-                            trigger:    $field.attr('data-bv-trigger'),
-                            message:    $field.attr('data-bv-message'),
-                            container:  $field.attr('data-bv-container'),
-                            selector:   $field.attr('data-bv-selector'),
-                            threshold:  $field.attr('data-bv-threshold'),
-                            validators: validators
-                        };
-
-                        // Check if there is any validators set using HTML attributes
-                        if (!$.isEmptyObject(opts.validators) && !$.isEmptyObject(opts)) {
+                                feedbackIcons: $field.attr('data-bv-feedbackicons'),
+                                trigger:       $field.attr('data-bv-trigger'),
+                                message:       $field.attr('data-bv-message'),
+                                container:     $field.attr('data-bv-container'),
+                                selector:      $field.attr('data-bv-selector'),
+                                threshold:     $field.attr('data-bv-threshold')
+                            },
+                            emptyOptions    = $.isEmptyObject(opts),        // Check if the field options are set using HTML attributes
+                            emptyValidators = $.isEmptyObject(validators);  // Check if the field validators are set using HTML attributes
+
+                        if (!emptyValidators || (!emptyOptions && that.options.fields[field])) {
+                            opts.validators = validators;
                             $field.attr('data-bv-field', field);
                             options.fields[field] = $.extend({}, opts, options.fields[field]);
                         }
@@ -332,7 +334,8 @@
 
             // Prepare the feedback icons
             // Available from Bootstrap 3.1 (http://getbootstrap.com/css/#forms-control-validation)
-            if (this.options.feedbackIcons
+            if (this.options.fields[field].feedbackIcons !== false && this.options.fields[field].feedbackIcons !== 'false'
+                && this.options.feedbackIcons
                 && this.options.feedbackIcons.validating && this.options.feedbackIcons.invalid && this.options.feedbackIcons.valid
                 && (!updateAll || index == total - 1))
             {

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


+ 14 - 11
src/js/bootstrapValidator.js

@@ -222,16 +222,18 @@
                         }
 
                         var opts = {
-                            trigger:    $field.attr('data-bv-trigger'),
-                            message:    $field.attr('data-bv-message'),
-                            container:  $field.attr('data-bv-container'),
-                            selector:   $field.attr('data-bv-selector'),
-                            threshold:  $field.attr('data-bv-threshold'),
-                            validators: validators
-                        };
-
-                        // Check if there is any validators set using HTML attributes
-                        if (!$.isEmptyObject(opts.validators) && !$.isEmptyObject(opts)) {
+                                feedbackIcons: $field.attr('data-bv-feedbackicons'),
+                                trigger:       $field.attr('data-bv-trigger'),
+                                message:       $field.attr('data-bv-message'),
+                                container:     $field.attr('data-bv-container'),
+                                selector:      $field.attr('data-bv-selector'),
+                                threshold:     $field.attr('data-bv-threshold')
+                            },
+                            emptyOptions    = $.isEmptyObject(opts),        // Check if the field options are set using HTML attributes
+                            emptyValidators = $.isEmptyObject(validators);  // Check if the field validators are set using HTML attributes
+
+                        if (!emptyValidators || (!emptyOptions && that.options.fields[field])) {
+                            opts.validators = validators;
                             $field.attr('data-bv-field', field);
                             options.fields[field] = $.extend({}, opts, options.fields[field]);
                         }
@@ -331,7 +333,8 @@
 
             // Prepare the feedback icons
             // Available from Bootstrap 3.1 (http://getbootstrap.com/css/#forms-control-validation)
-            if (this.options.feedbackIcons
+            if (this.options.fields[field].feedbackIcons !== false && this.options.fields[field].feedbackIcons !== 'false'
+                && this.options.feedbackIcons
                 && this.options.feedbackIcons.validating && this.options.feedbackIcons.invalid && this.options.feedbackIcons.valid
                 && (!updateAll || index == total - 1))
             {