From: "Jacques Le Roux" <[email protected]>
From: "David E Jones" <[email protected]>
On Sep 8, 2010, at 12:10 PM, Jacques Le Roux wrote:
I 1st tried to use it where it can be used (in the Java context, since it can't be used in the Ajax/DOM context as it's not
there
anymore, and that's what I mean by "useless in the autocomplete context") and
tried to play with it in
ModelFormField.renderLookupField where the autoCompleterTarget is used to build
the updateAreas (which is used after by
createAjaxParamsFromUpdateAreas to create the ajaxUrl(s) where all things are).
But the problem here is that it (Prototype Ajax.autocompleter) all depends on
the action on the field (2d arg of
ModelForm.UpdateArea). We don't have any actions from the user on the other
field (only letter typed in the lookup field are
handled by the autocompleter). I thought that I could find a way to trigger an action later in the process on the other field
(passed in updateAreas) but gave up at this stage because anyway I would still need to fill the field... There is maybe another
way, but I did not find it in the limited time I assigned to this. That's why I decided to use this hack.
In other words, there is no means in Prototype Ajax.autocompleter to fill a second field with a value of your choice grabbed
during
the server call. The afterUpdateElement callback (called setSelection in our case)
has only "two parameters, the input field
specified for autocompletion, and the selected item (the <li> item selected)". There are no places for the
description-field-name.
So we have to put a hack in the callback to handle the change in the other
field. It's the same in jQuery Autocomplete where
afterUpdateElement is named select, but there maybe something called change could be used (I doubt). Anyway the same problem
arises: where is the field we want to change and the value to put in it? If I missed something I would be happy to learn...
Yes, one way or another that method will need access to the information. It's
just code, so there's always a way...
It may be possible to put the information in a separately available structure
to avoid changing the Ajax.autocompleter code.
-David
Also there is an issue with how the code behaves for now. If you have 2 records with exactly the same name it can't retrieve the
related Id. This is I guess the reason why this have never been tried before.
This is due to these lines
if('UL'!= wrapperElement.firstDescendant().tagName ||
(wrapperElement.firstDescendant().childElements().length != 1)) {
//alert(transport.responseText); response is error or more than one entries
are found
return;
}
In such case we could retrieve the 1st one, with of course a message to alert
the user (you can't have the cake and eat it)
And in this message suggest them to use rather the lookup button, because then
there will be any ambiguities
Jacques
Jacques