浏览代码

#202, #206: Take the tab back. Automatically activate the tab containing the first invalid field

nghuuphuoc 11 年之前
父节点
当前提交
e2374511bc
共有 5 个文件被更改,包括 25 次插入21 次删除
  1. 1 3
      CHANGELOG.md
  2. 0 12
      demo/tab.html
  3. 11 2
      dist/js/bootstrapValidator.js
  4. 2 2
      dist/js/bootstrapValidator.min.js
  5. 11 2
      src/js/bootstrapValidator.js

+ 1 - 3
CHANGELOG.md

@@ -21,9 +21,7 @@ __New Features__
 * [#336](https://github.com/nghuuphuoc/bootstrapvalidator/issues/336): Add ```$field``` instance to the [callback validator](http://bootstrapvalidator.com/validators/callback/)
 
 __Changes__
-* [#42](https://github.com/nghuuphuoc/bootstrapvalidator/issues/42): Remove the submit button from ```submitHandler()```.
-You can use new ```getSubmitButton()``` method to get the clicked submit button
-* [#202](https://github.com/nghuuphuoc/bootstrapvalidator/issues/202), [#206](https://github.com/nghuuphuoc/bootstrapvalidator/issues/206): Does NOT active the tab containing the first invalid field automatically. The success/error tabs will NOT add custom CSS classes as well. These features are demonstrated in an example of using events
+* [#42](https://github.com/nghuuphuoc/bootstrapvalidator/issues/42): Remove the submit button from ```submitHandler()```. You can use new ```getSubmitButton()``` method to get the clicked submit button
 
 __Improvements__
 * [#244](https://github.com/nghuuphuoc/bootstrapvalidator/pull/244): Only enable the submit buttons if all fields are valid, thanks to [@smeagol74](https://github.com/smeagol74)

+ 0 - 12
demo/tab.html

@@ -139,18 +139,6 @@ $(document).ready(function() {
                 }
             }
         })
-        .on('error.form.bv', function(e) {
-            var $form         = $(e.target),
-                validator     = $form.data('bootstrapValidator'),
-                $invalidField = validator.getInvalidFields().eq(0),
-                $tabPane      = $invalidField.parents('.tab-pane'),
-                tabId         = $tabPane.attr('id');
-
-            // Activate the tab containing the invalid field if exists
-            if (tabId) {
-                $('a[href="#' + tabId + '"][data-toggle="tab"]').tab('show');
-            }
-        })
         .on('status.field.bv', function(e, data) {
             var $form     = $(e.target),
                 validator = $form.data('bootstrapValidator'),

+ 11 - 2
dist/js/bootstrapValidator.js

@@ -531,8 +531,17 @@
                 }
             }
 
-            // Focus to the first invalid field
-            this.$invalidFields.eq(0).focus();
+            var $invalidField = this.$invalidFields.eq(0);
+            if ($invalidField) {
+                // Activate the tab containing the invalid field if exists
+                var $tabPane = $invalidField.parents('.tab-pane'), tabId;
+                if ($tabPane && (tabId = $tabPane.attr('id'))) {
+                    $('a[href="#' + tabId + '"][data-toggle="tab"]').tab('show');
+                }
+
+                // Focus to the first invalid field
+                $invalidField.focus();
+            }
         },
 
         /**

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


+ 11 - 2
src/js/bootstrapValidator.js

@@ -530,8 +530,17 @@
                 }
             }
 
-            // Focus to the first invalid field
-            this.$invalidFields.eq(0).focus();
+            var $invalidField = this.$invalidFields.eq(0);
+            if ($invalidField) {
+                // Activate the tab containing the invalid field if exists
+                var $tabPane = $invalidField.parents('.tab-pane'), tabId;
+                if ($tabPane && (tabId = $tabPane.attr('id'))) {
+                    $('a[href="#' + tabId + '"][data-toggle="tab"]').tab('show');
+                }
+
+                // Focus to the first invalid field
+                $invalidField.focus();
+            }
         },
 
         /**