So I am wrestling with scriptaculous’s autocomplete form and trying to get hat up adn running. I have it working, but because I have CI’s pretty mod rewrite urls on, it requires a hack to hit the controller directly as well as discard the extra search prameters that you no longer need in order to get it to work. Has anyone else got it up and running with CI’s pretty urls? The hack isn’t that bad, but it is a hack.
Original instructions:
http://wiseguysonly.com/2006/04/14/ajax-autocompletion-for-the-impatient/
scriptaculous hack to make the URL mesh with CI’s pretty rewrite:
in getUpdatedChoices: function() inside controls.js:
new Ajax.Request(this.url, this.options);
becomes
new Ajax.Request(this.url + encodeURIComponent(this.getToken()), this.options);
My controller with a hack (explode line) to discard all of the scrptiaculous (search=xxx&_=...):
function autocomplete(){
$type = $this->uri->segment(3,'');
$table = $this->uri->segment(4,'');
$field = $this->uri->segment(5,'');
$prefix = $this->uri->segment(6,'');
$tmp_arr = explode(' search', $prefix);
$prefix = $tmp_arr[0];
$this->load->helper('autocomplete');
$this->data['Val'] = autocomplete($type,$table,$field,$prefix);
$this->load->show_smarty('generic_value.tpl',$this->data);
}
finally, to call the auto updater I changed the url to accept the controller path as well as the prefix to search for:
<form>
<input type="text" name="search" id="new_tag"/> <input type="submit" />
<div id="hints_tag"></div>
new Ajax.Autocompleter("new_tag","hints_tag","/assets/autocomplete/tag/tags/name/"+$F('new_tag'));</script>
</form>
