ソースを参照

#202: Activate tab containing the first invalid field

nghuuphuoc 11 年 前
コミット
80e49b498d

+ 1 - 0
CHANGELOG.md

@@ -3,6 +3,7 @@
 ## v0.4.3 (not released yet)
 
 * [#198](https://github.com/nghuuphuoc/bootstrapvalidator/pull/198): Add Canadian Postal Code support for the [```zipCode``` validator](http://bootstrapvalidator.com/validators/zip-code/), thanks to [@Francismori7](https://github.com/Francismori7)
+* [#202](https://github.com/nghuuphuoc/bootstrapvalidator/issues/202): Activate tab containing the first invalid field
 
 ## v0.4.2 (2014-04-19)
 

+ 8 - 0
dist/js/bootstrapValidator.js

@@ -346,7 +346,15 @@
                 // Focus to the first invalid field
                 if (this.$invalidField) {
                     this.$invalidField.focus();
+
+                    // Activate the tab containing the invalid field if exists
+                    var $tab = this.$invalidField.parents('.tab-pane'),
+                        tabId;
+                    if ($tab && (tabId = $tab.attr('id'))) {
+                        $('a[href="#' + tabId + '"][data-toggle="tab"]').trigger('click.bs.tab.data-api');
+                    }
                 }
+
                 return;
             }
 

ファイルの差分が大きいため隠しています
+ 2 - 1
dist/js/bootstrapValidator.min.js


+ 8 - 0
src/js/bootstrapValidator.js

@@ -345,7 +345,15 @@
                 // Focus to the first invalid field
                 if (this.$invalidField) {
                     this.$invalidField.focus();
+
+                    // Activate the tab containing the invalid field if exists
+                    var $tab = this.$invalidField.parents('.tab-pane'),
+                        tabId;
+                    if ($tab && (tabId = $tab.attr('id'))) {
+                        $('a[href="#' + tabId + '"][data-toggle="tab"]').trigger('click.bs.tab.data-api');
+                    }
                 }
+
                 return;
             }