PDA

View Full Version : Find invalid fields within complex form?



IvanJ
12 Nov 2009, 12:38 PM
There's a similar thread here: http://www.extjs.com/forum/showthread.php?t=82354

... but it doesn't address this question.

I have a FormPanel that has a complex layout (with nested fieldsets and panels).

When the user submits the form - if it has any invalid fields, I want to find the first one and focus on it.

Is there an easier way to do it than writing a recursive functions to loop through items.items[x].items.items type of deal and going through every single component until you find an invalid one?

Also, is there a better way to handle form submission than attaching a handler to a button? I've read a lot of ExtJS tutorials, but many of them are dated, so I'm thinking there's gotta be a better way.

12 Nov 2009, 1:10 PM
I tyipcally use the Container.findBy (or findByType) method and collect all field references, loop through those, and the first one that is invalid, i focus on.

This is a problem where Fields may be inside of nested tabs, etc. You would need much more logic than that.

IvanJ
13 Nov 2009, 12:18 PM
Another approach I found:



Ext.getCmp("studentFormPanel").getForm().getValues();


- This will return name:value pairs for all the fields inside the form, regardless of the layout. Then I could loop through them, get the first one that's invalid, and focus on it.

Thanks for all the screencasts, Jay!