Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #9882: patch_for_autocompleter_parameters.diff

File patch_for_autocompleter_parameters.diff, 3.2 kB (added by xutopia, 9 months ago)

Allow Hash or String As 'parameters' parameter in Ajax.AutoCompleter

  • test/functional/ajax_autocompleter_test.html

    old new  
    2626 
    2727<br/> 
    2828 
    29 Autocompleter ac2 w/ parameters: <input id="ac2" type="text" name="ac2"/> 
     29Autocompleter ac2 w/ parameters as a string: <input id="ac2" type="text" name="ac2"/> 
    3030<div id="ac2update" style="display:none;border:1px solid black;background-color:white;"></div> 
    3131 
    3232 
     
    3838 
    3939<br/> 
    4040 
    41 Autocompleter ac3 (nested in postion:relative div, selects "selectme" class): 
     41Autocompleter ac3 w/ parameters as a hash: <input id="ac3" type="text" name="ac3"/> 
     42<div id="ac3update" style="display:none;border:1px solid black;background-color:white;"></div> 
     43 
     44<script type="text/javascript" language="javascript" charset="utf-8"> 
     45// <![CDATA[ 
     46  new Ajax.Autocompleter('ac3','ac3update','_autocomplete_result.html',{parameters:{a: 'b', b: 'c'}}); 
     47// ]]> 
     48</script> 
     49 
     50<br/> 
     51 
     52Autocompleter ac4 (nested in postion:relative div, selects "selectme" class): 
    4253<br/>  
    4354<div style="position:relative"> 
    44 <input id="ac3" type="text"/> 
    45 <div id="ac3update" style="display:none;border:1px solid black;background-color:white;"></div> 
     55<input id="ac4" type="text"/> 
     56<div id="ac4update" style="display:none;border:1px solid black;background-color:white;"></div> 
    4657</div> 
    4758 
    4859<script type="text/javascript" language="javascript" charset="utf-8"> 
    4960// <![CDATA[ 
    50   new Ajax.Autocompleter('ac3','ac3update','_autocomplete_result.html',{select:'selectme'}); 
     61  new Ajax.Autocompleter('ac4','ac4update','_autocomplete_result.html',{select:'selectme'}); 
    5162// ]]> 
    5263</script> 
    5364 
    5465<br/><select><option>First Item</option><option>Second Item</option><option>Third Item</option></select> 
    5566 
    5667<br/><br/> 
    57 Autocompleter ac4 (autoselects option if single single option is returned): 
     68Autocompleter ac5 (autoselects option if single single option is returned): 
    5869<br/>  
    59 <input id="ac4" type="text"/> 
    60 <div id="ac4update" style="display:none;border:1px solid black;background-color:white;"></div> 
     70<input id="ac5" type="text"/> 
     71<div id="ac5update" style="display:none;border:1px solid black;background-color:white;"></div> 
    6172 
    6273<script type="text/javascript" language="javascript" charset="utf-8"> 
    6374// <![CDATA[ 
    64   new Ajax.Autocompleter('ac4','ac4update','_autocomplete_result_single.html',{select:'selectme',autoSelect:true}); 
     75  new Ajax.Autocompleter('ac5','ac5update','_autocomplete_result_single.html',{select:'selectme',autoSelect:true}); 
    6576// ]]> 
    6677</script> 
    6778 
  • src/controls.js

    old new  
    360360    this.options.parameters = this.options.callback ? 
    361361      this.options.callback(this.element, entry) : entry; 
    362362 
    363     if(this.options.defaultParams)  
    364       this.options.parameters += '&' + this.options.defaultParams; 
    365      
     363    if(this.options.defaultParams){ 
     364                        this.options.parameters += '&'  
     365                                + (typeof this.options.defaultParams == 'string' ?  
     366                                        this.options.defaultParams      :  
     367                                        $H(this.options.defaultParams).toQueryString()) 
     368                } 
    366369    new Ajax.Request(this.url, this.options); 
    367370  }, 
    368371