View Full Version : loop over form elements by index

15 Jan 2011, 3:20 AM
I have a formPanel, in a new opened newWindow. On loads, this form loads correctly and (according to the vtypes of each fields - let's said that there are, for simple example, a single textfield, or 2...) I correctly see it in red those fields that are not correct. But on a reset click, they are like some correct ones. So, i need to focus elements in a loop, or some. after focus AND blur then, each field looks correct (blue the correct ones, and red around the bad ones). Normally on submit, I verify them, and focus the bad ones automatically, but is nice that user knows that a field is bad without need to push the submit... The form is :

var edFrm=new Ext.form.FormPanel({
id:'myForm', reader:myReader, autoDestroy:true, monitorValid:true, trackResetOnLoad:true,
{ fieldLabel:'Id', id:'tabl_iden', xtype:'numberfield', value:'', readonly:true },
{ fieldLabel:'Text1', id:'tabl_titl', xtype:'textfield', value:'', allowBlank:false }
}); edFrm.getForm().load({url:myUrl+'?id='+pId+'&a='+pAct});

Then, on the window, a button which call edFrm.getForm().reset();. So 1 on 2 :
1. how to loop over each form elements (by index, not by name) like the old form['id'].elements[i]...
2. or some "magic" ext call fot that on reset, I can see all my fields like as I see them correctly marked (the god ones and the bad ones) without need to focus each of them.

15 Jan 2011, 5:19 AM
Don't completely understand your questions, but for (1), to loop through the fields on your form, you can use something like:



var fld;
for (var i = 0; i < edFrm.getForm().items.length; i++)
fld = edFrm.getForm().items[i];

15 Jan 2011, 5:38 AM
thanks fay. this :

works fine. but when I call then
Ext.getCmp(frm).getForm().items[3].focus(); this not works ! after refocus all the items, i try to focus the first visible elem, or the most important... (depends on each form...)
this can works if I call it directly as : Ext.getCmp(fieldId).focus(); because my Edit Form are all modal and of course there are not 2 fields with same name on the screen at the time...but correctly need to call this focus fromr inside the form...
so, please tell me how ?

15 Jan 2011, 5:44 AM
first, I made it with
for(var jj=0 ; jj<items.length ; jj++){ Ext.getCmp(items[jj]).focus(); }
and works. but your solution (Ext.getCmp(frm).getForm().items.each...) is more elegant.
in fact, instead calling by items, for setting (after an all refocus) a focus on first item I can just only call :
and this works. :-) thanks, again fay !

thread can be closed !