Browse Source

#121, #195: Use only one parameter to store the event data

nghuuphuoc 11 years ago
parent
commit
ed35946bd4

+ 6 - 6
demo/container4.html

@@ -163,17 +163,17 @@ $(document).ready(function() {
                 }
             }
         })
-        .on('error.field.bv', function(e, field, $field) {
+        .on('error.field.bv', function(e, data) {
             var $form    = $(e.target),
-                messages = $form.data('bootstrapValidator').getErrors($field);
-            $('#errors').find('li[data-bv-for="' + field + '"]').remove();
+                messages = $form.data('bootstrapValidator').getErrors(data.element);
+            $('#errors').find('li[data-bv-for="' + data.field + '"]').remove();
             for (var i in messages) {
-                $('<li/>').attr('data-bv-for', field).html(messages[i]).appendTo('#errors');
+                $('<li/>').attr('data-bv-for', data.field).html(messages[i]).appendTo('#errors');
             }
             $('#errors').parents('.form-group').removeClass('hide');
         })
-        .on('success.field.bv', function(e, field) {
-            $('#errors').find('li[data-bv-for="' + field + '"]').remove();
+        .on('success.field.bv', function(e, data) {
+            $('#errors').find('li[data-bv-for="' + data.field + '"]').remove();
         })
         .on('success.form.bv', function(e) {
             $('#errors')

+ 4 - 4
demo/dynamic.html

@@ -148,11 +148,11 @@
                     }
                 }
             })
-            .on('error.field.bv', function(e, field, $field) {
-                console.log(field, $field, '-->error');
+            .on('error.field.bv', function(e, data) {
+                console.log(data.field, data.element, '-->error');
             })
-            .on('success.field.bv', function(e, field, $field) {
-                console.log(field, $field, '-->success');
+            .on('success.field.bv', function(e, data) {
+                console.log(data.field, data.element, '-->success');
             });
     });
 </script>

+ 4 - 4
demo/dynamic2.html

@@ -119,11 +119,11 @@
                     }
                 }
             })
-            .on('error.field.bv', function(e, field, $field) {
-                console.log(field, $field, '-->error');
+            .on('error.field.bv', function(e, data) {
+                console.log(data.field, data.element, '-->error');
             })
-            .on('success.field.bv', function(e, field, $field) {
-                console.log(field, $field, '-->success');
+            .on('success.field.bv', function(e, data) {
+                console.log(data.field, data.element, '-->success');
             });
     });
 </script>

+ 6 - 6
demo/event.html

@@ -299,16 +299,16 @@ $(document).ready(function() {
             // If you want to prevent the default handler (bootstrapValidator._onSuccess(e))
             // e.preventDefault();
         })
-        .on('error.field.bv', function(e, field) {
-            //console.log(field, '-->error');
+        .on('error.field.bv', function(e, data) {
+            console.log(data.field, '-->error');
         })
-        .on('success.field.bv', function(e, field) {
-            //console.log(field, '-->success');
+        .on('success.field.bv', function(e, data) {
+            console.log(data.field, '-->success');
         })
-        .on('status.field.bv', function(e, field, $field, status) {
+        .on('status.field.bv', function(e, data) {
             var $form = $(e.target);
             // I don't want to add has-success class to valid field container
-            $field.parents('.form-group').removeClass('has-success');
+            data.element.parents('.form-group').removeClass('has-success');
 
             // I want to enable the submit button all the time
             $form.data('bootstrapValidator').disableSubmitButtons(false);

+ 0 - 164
demo/nameWithDot.html

@@ -1,164 +0,0 @@
-<!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>Example of using name with dot</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="user.firstName" placeholder="First name" />
-                    </div>
-                    <div class="col-lg-4">
-                        <input type="text" class="form-control" name="user.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="user.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="user.email" />
-                    </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="user.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="user.gender" value="male" /> Male
-                            </label>
-                        </div>
-                        <div class="radio">
-                            <label>
-                                <input type="radio" name="user.gender" value="female" /> Female
-                            </label>
-                        </div>
-                        <div class="radio">
-                            <label>
-                                <input type="radio" name="user.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: {
-                'user.firstName': {
-                    validators: {
-                        notEmpty: {
-                            message: 'The first name is required and cannot be empty'
-                        }
-                    }
-                },
-                'user.lastName': {
-                    validators: {
-                        notEmpty: {
-                            message: 'The last name is required and cannot be empty'
-                        }
-                    }
-                },
-                'user.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: 'user.password',
-                            message: 'The username and password cannot be the same as each other'
-                        }
-                    }
-                },
-                'user.email': {
-                    validators: {
-                        emailAddress: {
-                            message: 'The input is not a valid email address'
-                        }
-                    }
-                },
-                'user.password': {
-                    validators: {
-                        notEmpty: {
-                            message: 'The password is required and cannot be empty'
-                        },
-                        different: {
-                            field: 'user.username',
-                            message: 'The password cannot be the same as username'
-                        }
-                    }
-                },
-                'user.gender': {
-                    validators: {
-                        notEmpty: {
-                            message: 'The gender is required'
-                        }
-                    }
-                }
-            }
-        });
-});
-</script>
-</body>
-</html>

+ 4 - 4
demo/tab.html

@@ -151,10 +151,10 @@ $(document).ready(function() {
                 $('a[href="#' + tabId + '"][data-toggle="tab"]').tab('show');
             }
         })
-        .on('status.field.bv', function(e, field, $field, status) {
+        .on('status.field.bv', function(e, data) {
             var $form     = $(e.target),
                 validator = $form.data('bootstrapValidator'),
-                $tabPane  = $field.parents('.tab-pane'),
+                $tabPane  = data.element.parents('.tab-pane'),
                 tabId     = $tabPane.attr('id');
             if (tabId) {
                 var $tab = $('a[href="#' + tabId + '"][data-toggle="tab"]').parent();
@@ -162,9 +162,9 @@ $(document).ready(function() {
                 // Add custom class to tab containing the field
                 if ($tab) {
                     $tab.removeClass('tab-success').removeClass('tab-error');
-                    if (status == validator.STATUS_INVALID) {
+                    if (data.status == validator.STATUS_INVALID) {
                         $tab.addClass('tab-error').find('i').removeClass('fa-check').addClass('fa-times');
-                    } else if (status == validator.STATUS_VALID) {
+                    } else if (data.status == validator.STATUS_VALID) {
                         var isValidTab = validator.isValidContainer($tabPane);
                         $tab.addClass(isValidTab ? 'tab-success' : 'tab-error')
                             .find('i')

+ 13 - 3
dist/js/bootstrapValidator.js

@@ -559,7 +559,10 @@
                 if (index != -1) {
                     this.$invalidFields.splice(index, 1);
                 }
-                this.$form.trigger($.Event('success.field.bv'), [field, $field]);
+                this.$form.trigger($.Event('success.field.bv'), {
+                    field: field,
+                    element: $field
+                });
             }
             // If all validators are completed and there is at least one validator which doesn't pass
             else if (counter[this.STATUS_NOT_VALIDATED] == 0 && counter[this.STATUS_VALIDATING] == 0 && counter[this.STATUS_INVALID] > 0) {
@@ -567,7 +570,10 @@
                 if (index == -1) {
                     this.$invalidFields = this.$invalidFields.add($field);
                 }
-                this.$form.trigger($.Event('error.field.bv'), [field, $field]);
+                this.$form.trigger($.Event('error.field.bv'), {
+                    field: field,
+                    element: $field
+                });
             }
         },
 
@@ -837,7 +843,11 @@
             }
 
             // Trigger the "status.field.bv" event
-            this.$form.trigger($.Event('status.field.bv'), [field, $field, status]);
+            this.$form.trigger($.Event('status.field.bv'), {
+                field: field,
+                element: $field,
+                status: status
+            });
 
             this._onValidateFieldCompleted($field);
 

File diff suppressed because it is too large
+ 2 - 2
dist/js/bootstrapValidator.min.js


+ 13 - 3
src/js/bootstrapValidator.js

@@ -558,7 +558,10 @@
                 if (index != -1) {
                     this.$invalidFields.splice(index, 1);
                 }
-                this.$form.trigger($.Event('success.field.bv'), [field, $field]);
+                this.$form.trigger($.Event('success.field.bv'), {
+                    field: field,
+                    element: $field
+                });
             }
             // If all validators are completed and there is at least one validator which doesn't pass
             else if (counter[this.STATUS_NOT_VALIDATED] == 0 && counter[this.STATUS_VALIDATING] == 0 && counter[this.STATUS_INVALID] > 0) {
@@ -566,7 +569,10 @@
                 if (index == -1) {
                     this.$invalidFields = this.$invalidFields.add($field);
                 }
-                this.$form.trigger($.Event('error.field.bv'), [field, $field]);
+                this.$form.trigger($.Event('error.field.bv'), {
+                    field: field,
+                    element: $field
+                });
             }
         },
 
@@ -836,7 +842,11 @@
             }
 
             // Trigger the "status.field.bv" event
-            this.$form.trigger($.Event('status.field.bv'), [field, $field, status]);
+            this.$form.trigger($.Event('status.field.bv'), {
+                field: field,
+                element: $field,
+                status: status
+            });
 
             this._onValidateFieldCompleted($field);