From 42b41c500aace0450d8b3ea76d26c2420cf18f84 Mon Sep 17 00:00:00 2001 From: Cameron Date: Mon, 15 Apr 2013 14:07:47 -0700 Subject: [PATCH] Switch to appropriate tab when html5 validation fails --- e107_web/js/core/admin.jquery.js | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/e107_web/js/core/admin.jquery.js b/e107_web/js/core/admin.jquery.js index b40132841..1ff88b06e 100644 --- a/e107_web/js/core/admin.jquery.js +++ b/e107_web/js/core/admin.jquery.js @@ -32,10 +32,31 @@ $(document).ready(function() }) }); + /* Switch to Tab containing invalid form field. */ + $('input[type=submit],button[type=submit]').on('click', function() { + + var id = $(this).closest('form').attr('id'); + var found = false; + + $('#'+id).find(':invalid').each(function(index, node) { + + var tab = $('#'+node.id).closest('.tab-pane').attr('id'); + + if(tab && (found == false)) + { + $('a[href="#'+tab+'"]').tab('show'); + found = true; + //alert(node.id+' : '+tab); + } + // var label = $('label[for=' + node.id + ']'); + }) + + return true; + }); + + - - // run tips on title attribute. $(".e-tip").each(function() {