That solution would work as well, but why would we need the delay of 500 ms to hide the autosuggest box? Is that a pure cosmetic solution or does it add any functionality?
I'd rather remove the setTimeout if we do not need it then adding a change event trigger and setting 2 flags to avoid triggering the change event again. That just doesn't feel right... -----Original Message----- From: andrea del bene [mailto:[email protected]] Sent: Tuesday, July 21, 2015 10:40 To: [email protected] Subject: Re: Autocomplete event flow bug Hi, I'd rather trigger 'change' event before calling 'window.setTimeout(hideAutoComplete, 500);'. To avoid 'change' to be called twice, we can set flag 'triggerChangeOnHide = false' and 'visible = 0 ' On 20/07/2015 16:58, Elger van Boxtel wrote: > > Hi All, > > I'm having a problem with the current implementation of the > autocomplete. Let me explain first: > > I have a form with a autocomplete field (AutoCompleteBehavior) and a > saveAjaxButtonon it. Apart from this, this field has a onchange > AjaxEventBehaviourto do some validation on the backend and possibly > make some changes to the field. > > When I fill in the field and without leaving the field (and thus no > blur event has been triggered yet) I click on the save AjaxButton. > > What I'd expect to happen is the following event flow: > > -*blur*: the field has been blurred > > -*change*: the field has been changed > > -*click*: the click on the save button > > Instead this is what happens: > > -*blur* > > -*click* > > -*change* > > Further investigation tells me that this is because of the > wicket-autocomplete.jsimplementation for the blurevent handler. > > wicket-autocomplete.js can be found > on:\wicket-head\wicket\wicket-extensions\src\main\java\org\apache\wick > et\extensions\ajax\markup\html\autocomplete > > On line 91 the blur event hander can be found: > > Wicket.Event.add(obj, 'blur', function (jqEvent) { > > window.setTimeout(hideAutoComplete, 500); > > }); > > This wraps the hideAutoCompletefield in a setTimeoutof 500 ms. In the > hideAutoComplete, the changeevent is triggered (line 438). > > The setTimout call causes the change event to be executed after the > click event, leaving me with a partially saved form. > > To fix this, I could remove the setTimeoutfunctionality from the > blurevent handler. This will call hideAutoCompleteimmediately. This > change will cause the autocomplete dialog to be closed immediately and > leaving us with the right event stack. I've not noticed any other side > effects. > > I have a patch ready, but I'd like to have your thoughts on this. When > necessary, I can create an issue on https://issues.apache.org and send > a pull request. > > All code has been taken from latest greatest Wicket on Github. > > With kind regards, > > Elger van Boxtel > Agile Developer > -------------------- > *Planon B.V.* > Postbus 38074 > 6503 AB Nijmegen > > Wijchenseweg 8 > 6537 TL Nijmegen > > Nederland > T: +31 (0) 24 750 7727 > > F: +31 (0) 24 642 2942 > > *E*: [email protected] <mailto:[email protected]> > *W*: www.planon.nl <http://www.planon.nl/> > > *W*: http://elgervanboxtel.nl > > *LN*: LinkedIn <https://nl.linkedin.com/in/elgervanboxtel> > > *GH:* GitHub <https://github.com/elgervb>_ > > This e-mail and any attachment is for authorized use by the intended > recipient(s) only. It may contain proprietary material, confidential > information and/or be subject to legal privilege. It should not be > copied, disclosed to, retained or used by, any other party. If you are > not an intended recipient then please promptly delete this e-mail and > any attachment and all copies and inform the sender. > > ***Please consider the environment before printing this e-mail*. >
