EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: Stefan B. on March 02, 2015, 03:51:36 AM



Title: How can I set the focus on a datagrid cell that has validation error
Post by: Stefan B. on March 02, 2015, 03:51:36 AM
When I will save a row and there is a roq validation error.
How can I set the focus on the first datagrid cell that has validation error?


Title: Re: How can I set the focus on a datagrid cell that has validation error
Post by: stworthy on March 03, 2015, 08:22:06 PM
Please extend a new method to achieve this functionality.
Code:
$.extend($.fn.datagrid.methods, {
    focusInvalidField: function(jq, index){
        return jq.each(function(){
            var target = this;
            var tr = $.data(target, 'datagrid').options.finder.getTr(target, index);
            if (!tr.hasClass('datagrid-row-editing')){
                return true;
            }
            var invalidbox = tr.find('.validatebox-invalid');
            invalidbox.filter(':not(:disabled):first').focus();
        })
    }
})

Usage example:
Code:
var index = 2;
$('#dg').datagrid('focusInvalidField', index);


Title: Re: How can I set the focus on a datagrid cell that has validation error
Post by: Stefan B. on March 05, 2015, 12:36:09 AM
Hello and thx for this sollution. It works fine  :D