Paul Shannon
2005-Aug-05 04:38 UTC
[Rails-spinoffs] Quick Question on Autocompleter Parameters
Hello, Is it possible to send the current value of a second form element with the AJAX request on the Autocompleter? At the moment, I initialise the Autocompleter on page load, so any parameters passed in the constructor are given the value set at page load time. I need to obviously pass in the value of the second form element when the autocompleter is called. Does this function already exist, or where should I look to try and add it? Thanks Paul Shannon Web Applications Developer Codeweavers Limited
Rob Sharp
2005-Aug-05 06:15 UTC
[Rails-spinoffs] Quick Question on Autocompleter Parameters
On 8/5/05, Paul Shannon <Paul.Shannon@codeweavers.net> wrote:> Hello,Hey,> > > Is it possible to send the current value of a second form element with > the AJAX request on the Autocompleter? At the moment, I initialise the > Autocompleter on page load, so any parameters passed in the constructor > are given the value set at page load time. I need to obviously pass in > the value of the second form element when the autocompleter is called. > > Does this function already exist, or where should I look to try and add > it?I don''t think you can do this with the stock source, but if you look at the getUpdatedChoices method, you can see where it builds the URL that is passed to the AJAX handler. You could either hack this for your specific needs (bad!) or you could implement something that takes an array of input names in preference to a single input name and build the URI based on the contents of the array. I''m sure you won''t be the only person to want to do this, so option 2 would be nice, if you have the time :-) Hope that helps, Rob.> > Thanks > > > Paul Shannon > > Web Applications Developer > Codeweavers Limited > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >-- Rob Sharp email/jabber: rob@sharp.id.au web: http://sharp.id.au pgp: 0E2C C63B BA04 DEB4 7CC0 84FD 17E3 6AA4 87FB 62DF
Paul Shannon
2005-Aug-05 10:22 UTC
[Rails-spinoffs] Quick Question on Autocompleter Parameters
Thanks for the hint Rob, I have this working for me now, I simply add an array of text field IDs when creating a new Autocomplete instance: ... parameters: new Array(''formfield1'', ''formfield2'') ... The edited getUpdatedChoices function is as follows: [code] getUpdatedChoices: function() { entry = encodeURIComponent(this.element.name) + ''='' + encodeURIComponent(this.getEntry()); this.options.parameters = this.options.callback ? this.options.callback(this.element, entry) : entry; if(this.options.defaultParams) { //EDIT: Paul Shannon Codeweavers Ltd 2005 if(typeof(this.options.defaultParams) == typeof("")) { this.options.parameters += ''&'' + this.options.defaultParams; } else { for (var count = 0; count < this.options.defaultParams.length; count++) { this.options.parameters += ''&'' + document.getElementById(this.options.defaultParams[count]).name + ''='' + document.getElementById(this.options.defaultParams[count]).value; } } } new Ajax.Request(this.url, this.options); }, [/code] Hopefully this can be included without side effecting the stock method of passing POST parameters. It doesn''t effect anything in my use case but others may differ. Please feel free to include this in the main stock code if everyone feels it works well. Paul -----Original Message----- From: Rob Sharp [mailto:rob.sharp@gmail.com] Sent: 05 August 2005 13:08 To: Paul Shannon; rails-spinoffs@lists.rubyonrails.org Subject: Re: [Rails-spinoffs] Quick Question on Autocompleter Parameters On 8/5/05, Paul Shannon <Paul.Shannon@codeweavers.net> wrote:> Hello,Hey,> > > Is it possible to send the current value of a second form element with > the AJAX request on the Autocompleter? At the moment, I initialise the > Autocompleter on page load, so any parameters passed in theconstructor> are given the value set at page load time. I need to obviously pass in > the value of the second form element when the autocompleter is called. > > Does this function already exist, or where should I look to try andadd> it?I don''t think you can do this with the stock source, but if you look at the getUpdatedChoices method, you can see where it builds the URL that is passed to the AJAX handler. You could either hack this for your specific needs (bad!) or you could implement something that takes an array of input names in preference to a single input name and build the URI based on the contents of the array. I''m sure you won''t be the only person to want to do this, so option 2 would be nice, if you have the time :-) Hope that helps, Rob.> > Thanks > > > Paul Shannon > > Web Applications Developer > Codeweavers Limited > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >-- Rob Sharp email/jabber: rob@sharp.id.au web: http://sharp.id.au pgp: 0E2C C63B BA04 DEB4 7CC0 84FD 17E3 6AA4 87FB 62DF