PDA

View Full Version : formAutoFocus: Setting the focus for a form.



jmariani
1 Dec 2008, 5:28 PM
Hi.

I needed to set the focus to the first field on a form when it's shown, so I developed this small plugin to do that.
The only thing I couldn't figure how to fix is the field to be validated when it get the focus.

Hope it helps somebody.


bdApp.formAutoFocus = function (){

return{

init : function (form){
//Try to get the first focusable field.
form.on('afterlayout', function(){
Ext.each(this.items.items,
function(item, index, allItems){
switch (item.getXType()) {
case 'hidden':
return true;
break;
default:
if (!item.disabled) {
item.suspendEvents();
item.focus(true, true);
//item.clearInvalid();
item.resumeEvents();
return false;
}
}
}
);

});
}

}

};

Cya.

Fabyo
2 Dec 2008, 5:10 AM
I think this plugin is useless, there simple ways to put a focus on the field, without specifying the plugin

jmariani
2 Dec 2008, 6:54 AM
I think this plugin is useless, there simple ways to put a focus on the field, without specifying the plugin

You're right, probably there are more than one way to crack eggs. Would you mind to share yours?

Cya.