EasyUI Forum
September 14, 2025, 10:36:00 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: switch to focus a tab on a validation error  (Read 7358 times)
fguibert
Newbie
*
Posts: 23


View Profile
« on: March 01, 2019, 04:19:08 AM »

Hi,
I have a form dispatched in several Jeasyui tabs.
when I submit my form on the last tab and forgot to fill a mandatory input in the first tab, nothing happen because validation function do not raise/focus on the fisrt tab to show the error.

is it possible to raise the tab containing the error ?

I saw a invalidHandler in JQuery but don't seems to work with Jeasyui :

Code:
$(function(){
    $('#formAbonne').form({
        ajax:false,
        onSubmit:function(){
            return $(this).form('validate');
        },
        invalidHandler: function(e, validator){
            if(validator.errorList.length)
            $('#tabs a[href="#' + jQuery(validator.errorList[0].element).closest(".tab-pane").attr('id') + '"]').tab('show')
        }
    });
});
Logged
jarry
Administrator
Hero Member
*****
Posts: 2298


View Profile Email
« Reply #1 on: March 04, 2019, 07:22:00 AM »

Please refer to this code.
Code:
$('#ff').form('submit', {
onSubmit: function(){
var form = $(this);
var isValid = form.form('validate');
if (!isValid){
var field = form.find('.validatebox-invalid:first');
var panels = $('#tabs').tabs('tabs');
for(var i=0; i<panels.length; i++){
var panel = panels[i];
if (panel.has(field).length){
var index = $('#tabs').tabs('select', i);
setTimeout(function(){
field.focus();
},0)
break;
}
}
}

return isValid;
}
})
Logged
fguibert
Newbie
*
Posts: 23


View Profile
« Reply #2 on: March 04, 2019, 08:45:20 AM »

thanks a lot jarry, it works great !
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!