Thank you Ron, that helps a lot!
However I am experiencing a problem.
I am getting a JS error "element is not defined". Also the
afterupdateelement is running directly when the page loads, maybe that's
the cause of the problem.
Here is my autocomplete script.
new Ajax.Autocompleter('contact_name', 'contact_name_auto_complete',
'http://localhost/ajax/act_people.cfm', {
afterUpdateElement:loadSelection(element,selectedElement),
paramName:"contact", frequency:0.1 })
Thanks for your time,
Daniel
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Rob
Wills
Sent: Thursday, December 08, 2005 12:03 AM
To: [email protected]
Subject: Re: [Rails-spinoffs] AutoCompleter afterUpdateElement
On 08/12/2005, at 4:38 PM, Daniel Elmore wrote:
> Any ideas how I can submit say, a person ID instead of the person's
> name
> on an autocompleter input field? Surely this is a common need.
>
It is... and it's in the documentation (although it's not obvious how
to achieve it)
Use an `afterUpdateElement:` option for the new Ajax.autocompleter().
http://wiki.script.aculo.us/scriptaculous/show/Ajax.Autocompleter
I do something similar but I handle it in a slightly more transparent
way... I let the autocompleter display the name, but take action
based on the ID of the <li> element that was returned from the
server. You can't really just use raw numbers as DOM element IDs, so
I format mine as:
<li id="entityType::entityId">Entity description</li>
e.g.
<li id="Fabric::24">Cross Dyed Cotton</li>
My afterUpdateElement option function extracts the entity type and
id, then uses it to load a preview of the selected entity:
loadresult: function(element,selectedElement) {
var entityParts = selectedElement.id.split('::');
var entityType = entityParts[0];
var entityId = entityParts[1];
...
If you want to keep it simple - and use the person's ID in the input
field - just set the value of the input field to the entityID parsed
from the selected element.
Hope that helps.
Cheers,
Rob_______________________________________________
Rails-spinoffs mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
_______________________________________________
Rails-spinoffs mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs