PDA

View Full Version : Why is monitorValid implemented with polling instead of events?



Uberdude
18 Oct 2010, 2:38 AM
Why does the monitorValid config option for a FormPanel set up a periodic task to query the valid state of the form? I'd have thought a better approach would be to attach listeners to the valid and invalid events of the contained form fields. That way you'd only fire a clientvalidationchanged event when it changed, and not pointlessly revalidate the form when the user has gone to make a cup of coffee. This does cause real performance problems if the validation of the fields calls the server. Also the validate state of the form may change and if the poll interval is too big then you could end up clicking a formBind-ed button which should have been disabled. Events rather than polling are usually a superior design: buttons fire a click event, we don't poll them asking if they have been clicked!

plalx
18 Oct 2010, 5:35 AM
I'am not sure either why they have choosed that design... at first glance it looks inefficient...

Condor
18 Oct 2010, 6:16 AM
Animal already commented on this some time ago.

The problem is mainly that some fields can change without ever fireing an event that you could use for monitoring.

e.g. Try pasting a text in a TextField.

Uberdude
20 Oct 2010, 3:51 AM
Condor, thanks, here is the link to Animal's thread for reference. http://www.sencha.com/forum/showthread.php?96058-OPEN-818-FormPanel-monitorValid-to-update-on-bubbled-valid-invalid-events

So it seems bubbling on child valid events would be better, but the problem is valid/invalid are not called sometimes when they should as you say on that thread, e.g. on paste using mouse (Ctrl+V is ok) into a TextField as the valid event is on keyup. The fact Ext's change event is not always fired when the value in a field changes but only on blur has caused me problems in the past. Using key events as a workaround, as the Ext authors have for validation, misses some cases.

So it seems to me the best solution is for all fields to get a 'proper' change event that fires whenever the field changes, regardless of how that change comes about (keyboard, mouse, crazy accessibility input device, programatically etc.) and without needed to blur. Maybe this is hard, but I think it would be very useful. This could then trigger the valid event, which could then bubble up for the form's monitorValid.

Condor
20 Oct 2010, 4:03 AM
Ext has to rely on the browser for this kind of events and there just isn't a universal 'change' event for <input>s.

Uberdude
21 Oct 2010, 2:10 PM
I see. I feared there may be such a problem given a universal change event seems an obviously good thing to have were it possible.