PDA

View Full Version : TextField does not sink Event.ONCHANGE



mbellew
6 May 2010, 8:39 AM
I've been struggling to get selenium to work since I switched some TextBox controls to TextField. It seems to TextField never fires change events in the test harness. The best I can tell the difference is that TextBox sinks and dispatches the Event.ONCHANGE, while TextField does not. TextField only sinks ONBLUR to fire change events.

Under normal usage this does not seem to be a problem, however, in the test harness it is seems to be exceedingly hard to get these controls to work at all.

Ideas?

Thanks,
Matt

sven
6 May 2010, 8:41 AM
And why this is a bug? Moving this to thehelp forum. Please read the bugforum guidelines for future posts in that forum

mbellew
6 May 2010, 11:42 AM
Fair enough, this may not be a bug, but I believe a fix will require a code change. To verify my guess I wrote this code below, and indeed this seems to work. (I realize there are issues with correctly handling change caused by a blur...). Unfortunately, this is not a complete solution because of all the many classes that extend TextField.

I don't understand all the mysteries surrounding the selenium test harness, but without a fix (along these lines or not), it is nearly impossible to adopt ext-gwt due to testability.


private class _TextField<D> extends TextField<D>
{
public _TextField()
{
sinkEvents(Event.ONCHANGE);
}

public void onComponentEvent(ComponentEvent ce)
{
super.onComponentEvent(ce);
if (ce.getEventTypeInt() == Event.ONCHANGE)
{
onChange(ce);
}
}

// TODO avoid double fireChangeEvent() on blur
protected void onChange(ComponentEvent be)
{
D v = getValue();
value = v;
fireChangeEvent(focusValue, v);
}
}