![]() |
|
Snippets |
|
Sometimes in the generator you have a large listing of elements in a admin_double_list.
Well I wanted to write a quick little autocomplete text box that would search for results and when you selected one, it would be added into the associated select box.
In your generator add a new partial: edit: display: [ _quick_search ]
Create a file in your templates directory called _quick_search.php
Copy this code in there:
===CODE===
<?php $response = sfContext::getInstance()->getResponse(); $response->addJavascript(sfConfig::get('sf_prototype_web_dir').'/js/prototype'); $response->addJavascript(sfConfig::get('sf_prototype_web_dir').'/js/effects'); $response->addJavascript(sfConfig::get('sf_prototype_web_dir').'/js/controls'); $response->addStylesheet(sfConfig::get('sf_prototype_web_dir').'/css/input_auto_complete_tag'); ?> <input type="text" id="quick_search" name="quick_search"/>
<div class="auto_complete" id="quick_search_auto_complete" style="position: absolute; left: 445px; top: 421px; width: 113px; opacity: 0.17329; display: none;">
</div>
<script type="text/javascript">
//<![CDATA[
function addSelection (li)
{
$('associated_titles').options[ $('associated_titles').options.length] = new Option (li.childNodes[0].nodeValue, li.id);
}
new Ajax.Autocompleter('quick_search', 'quick_search_auto_complete', '/backend_dev.php/search', { updateElement: addSelection });
//]]>
</script>
===CODE===
Make sure you change your url from /backend_dev.php/search to whatever your action that will search your database and your good to go!
Just FYI: You can use the Symfony helper autocomplete_tag () because it does not allow for passing the updateElement parameter.