[Catalyst] Prototype: what determines replaced text for complex autocomplete?

Dobrica Pavlinusic dpavlin at rot13.org
Tue Nov 29 23:02:04 CET 2005


On Mon, Nov 28, 2005 at 01:54:01PM -0800, Bill Moseley wrote:
> http://script.aculo.us/demos/ajax/autocompleter_customized
> 
> Here's the HTML and call to Autocompleter:
> 
> To: <br/>
>   <input autocomplete="off" id="message_to" name="message[to]" size="30" type="text" value="" />
>   <div class="auto_complete" id="message_to_auto_complete"></div>
>   <script type="text/javascript">new Ajax.Autocompleter('message_to', 'message_to_auto_complete', '/demos/ajax/auto_complete_for_message_to', {})
>   </script><br/>
> 
> 
> The ajax request returns a complex list item:  (sorry for the wide
> output)
> 
> $ GET 'http://script.aculo.us/demos/ajax/auto_complete_for_message_to?message[to]=a'
> <ul class="contacts">
>   <li class="contact"><div class="image"><img src="/demos/images/contacts/5.jpg"/></div><div class="name">Ada Noel</div><div class="email"><span class="informal">ada at noel.fake</span></div></li>
>   <li class="contact"><div class="image"><img src="/demos/images/contacts/8.jpg"/></div><div class="name">Adlai Cathy</div><div class="email"><span class="informal">adlai at cathy.fake</span></div></li>
>   <li class="contact"><div class="image"><img src="/demos/images/contacts/3.jpg"/></div><div class="name">Adrian Audrey</div><div class="email"><span class="informal">adrian at audrey.fake</span></div></li>
>   [...]
> </ul>
> 
> What I don't see is what says to use "name" as the text to replace?
> 
> That is, when the pop-up list is shown and I click on a name, what
> says to update the text field with the name (instead of the email, for
> example)?

When entry is selected (in controls.js) it calls select_entry which in
turn ignores elements with class 'informal':

  select_entry: function() {
    this.active = false;
    value = Element.collectTextNodesIgnoreClass(this.get_current_entry(), 'informal').unescapeHTML();
    this.updateElement(value);
    this.element.focus();
  },

It should probably be parametar or just documented :-)

-- 
Dobrica Pavlinusic               2share!2flame            dpavlin at rot13.org
Unix addict. Internet consultant.             http://www.rot13.org/~dpavlin




More information about the Catalyst mailing list