Michael Roper
2005-Sep-22 02:36 UTC
[Rails-spinoffs] Autocomplete - setting a second value?
I''m using the autocomplete function, and need a way to grab a second value from the ajax request... an example would probably speak better: This is my HTML: <input name="CustomerName" id="CustomerName" type="text" /> <div id="CustomerList"></div> <input name="CustomerID" id="CustomerID" type="hidden" /> <script>new Ajax.Autocompleter(''CustomerName'',''CustomerList'',''crmLookup.aspx'', {});</script> And this is my ajax response: <ul class="acList"> <li class="acResult">Customer One<span class="informal">cid001</span></li> <li class="acResult">Customer Two<span class="informal">cid002</span></li> <li class="acResult">Customer Three<span class="informal">cid003</span></li> <li class="acResult">Customer Four<span class="informal">cid004</span></li> <li class="acResult">Customer Five<span class="informal">cid005</span></li> </ul> Now in the same way the text ''Cutomer One'' gets put back into the ''CustomerName'' text field, is there any way that I can grab the ''cid001'' text (that is hidden with the ''informal'' class), and dump it back into the hidden ''CustomerID'' at the same time? Regards, Michael ------------------------------------------ Michael Roper - Web Developer WORLDWIDE ONLINE PRINTING AUST/NZ [E michael.roper@worldwide.com.au] [W http://www.worldwide.com.au] ------------------------------------------
Ron Piterman
2005-Sep-22 14:05 UTC
[Rails-spinoffs] Autocomplete - setting a second value?
It seems you can extends the class with the function updateElement(arg). arg is the <li element. Never tried this, just found it in the source... ????? Michael Roper:> I''m using the autocomplete function, and need a way to grab a second > value from the ajax request... an example would probably speak better: > > This is my HTML: > > <input name="CustomerName" id="CustomerName" type="text" /> > <div id="CustomerList"></div> > <input name="CustomerID" id="CustomerID" type="hidden" /> > <script>new > Ajax.Autocompleter(''CustomerName'',''CustomerList'',''crmLookup.aspx'', > {});</script> > > And this is my ajax response: > > <ul class="acList"> > <li class="acResult">Customer One<span > class="informal">cid001</span></li> > <li class="acResult">Customer Two<span > class="informal">cid002</span></li> > <li class="acResult">Customer Three<span > class="informal">cid003</span></li> > <li class="acResult">Customer Four<span > class="informal">cid004</span></li> > <li class="acResult">Customer Five<span > class="informal">cid005</span></li> > </ul> > > Now in the same way the text ''Cutomer One'' gets put back into the > ''CustomerName'' text field, is there any way that I can grab the > ''cid001'' text (that is hidden with the ''informal'' class), and dump it > back into the hidden ''CustomerID'' at the same time? > > > Regards, > > Michael > ------------------------------------------ > Michael Roper - Web Developer > WORLDWIDE ONLINE PRINTING AUST/NZ > [E michael.roper@worldwide.com.au] > [W http://www.worldwide.com.au] > ------------------------------------------ > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > >
Michael Roper
2005-Sep-23 01:40 UTC
[Rails-spinoffs] Autocomplete - setting a second value?
Not sure what you mean there, and if it would solve my problem... Is there any way I can trigger another function when an item from the list is selected? Then I could possibly try and grab the second bit of data and put it into the hidden field... Any ideas, anyone? On 23/09/2005, at 3:41 AM, Ron Piterman wrote:> It seems you can extends the class with the function > updateElement(arg). > arg is the <li element. > Never tried this, just found it in the source... > > > ????? Michael Roper: > >> I''m using the autocomplete function, and need a way to grab a second >> value from the ajax request... an example would probably speak >> better: >> >> This is my HTML: >> >> <input name="CustomerName" id="CustomerName" type="text" /> >> <div id="CustomerList"></div> >> <input name="CustomerID" id="CustomerID" type="hidden" /> >> <script>new >> Ajax.Autocompleter(''CustomerName'',''CustomerList'',''crmLookup.aspx'', >> {});</script> >> >> And this is my ajax response: >> >> <ul class="acList"> >> <li class="acResult">Customer One<span >> class="informal">cid001</span></li> >> <li class="acResult">Customer Two<span >> class="informal">cid002</span></li> >> <li class="acResult">Customer Three<span >> class="informal">cid003</span></li> >> <li class="acResult">Customer Four<span >> class="informal">cid004</span></li> >> <li class="acResult">Customer Five<span >> class="informal">cid005</span></li> >> </ul> >> >> Now in the same way the text ''Cutomer One'' gets put back into the >> ''CustomerName'' text field, is there any way that I can grab the >> ''cid001'' text (that is hidden with the ''informal'' class), and dump it >> back into the hidden ''CustomerID'' at the same time? >> >> >> Regards, >> >> Michael >> ------------------------------------------ >> Michael Roper - Web Developer >> WORLDWIDE ONLINE PRINTING AUST/NZ >> [E michael.roper@worldwide.com.au] >> [W http://www.worldwide.com.au] >> ------------------------------------------ >> >> _______________________________________________ >> Rails-spinoffs mailing list >> Rails-spinoffs@lists.rubyonrails.org >> http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >> >> > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >
François Beausoleil
2005-Sep-23 10:38 UTC
[Rails-spinoffs] Autocomplete - setting a second value?
Hello Michael, Michael Roper said the following on 2005-09-23 01:16:> Not sure what you mean there, and if it would solve my problem... > > Is there any way I can trigger another function when an item from the > list is selected? > Then I could possibly try and grab the second bit of data and put it > into the hidden field... > > Any ideas, anyone?Seems my previous mail got lost on the way. I sent it about two days ago... Anyway, scriptaculous trunk has a nice feature - afterUpdateElement is a callback that will be triggered after the element has been updated. The callback receives two parameters - the element that was updated, and the element that was selected. In my app, I grab the selection''s ID, parse it, and set a hidden field with that value. Bye ! Fran?ois
Michael Roper
2005-Sep-26 02:10 UTC
[Rails-spinoffs] Autocomplete - setting a second value?
Thanks Fran?ois.. When you say its in the trunk, is it in the latest 1.5 RC1? ... and if so, would it be possible for you to show some code so I can see how you exactly do it? It would be much appreciated! Cheers Michael On 23/09/2005, at 10:15 PM, Fran?ois Beausoleil wrote:> Hello Michael, > > Michael Roper said the following on 2005-09-23 01:16: > >> Not sure what you mean there, and if it would solve my problem... >> Is there any way I can trigger another function when an item from >> the list is selected? >> Then I could possibly try and grab the second bit of data and put >> it into the hidden field... >> Any ideas, anyone? >> > > Seems my previous mail got lost on the way. I sent it about two > days ago... Anyway, scriptaculous trunk has a nice feature - > afterUpdateElement is a callback that will be triggered after the > element has been updated. The callback receives two parameters - > the element that was updated, and the element that was selected. > > In my app, I grab the selection''s ID, parse it, and set a hidden > field with that value. > > Bye ! > Fran?ois > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >
François Beausoleil
2005-Sep-26 14:05 UTC
Re: [Rails-spinoffs] Autocomplete - setting a second value?
Hello Michael, Michael Roper said the following on 2005-09-26 01:46:> When you say its in the trunk, is it in the latest 1.5 RC1?Yes, exactly. You can get the latest version at http://dev.rubyonrails.com/browser/spinoffs/scriptaculous/> ... and if so, would it be possible for you to show some code so I can > see how you exactly do it?Sure, no problem. app/views/products/_form.rhtml: <%= hidden_field :product, :supplier_id %> <%= text_field :supplier, :name, :size => 40, :value => @product.supplier.nil? ? nil : @product.supplier.display_name %> <div class="auto_complete" id="supplier_name_auto_complete"/> <script type="text/javascript"> new Ajax.Autocompleter(''supplier_name'', ''supplier_name_auto_complete'', ''/products/auto_complete_for_supplier_name'', {afterUpdateElement: function(element, selectedElement) { $(''product_supplier_id'').value = selectedElement.id.substring(1);}});</script> app/views/products/auto_complete_for_supplier_name.rhtml: <ul> <%= render :partial => ''supplier'', :collection => @suppliers %> </ul> app/views/products/_supplier.rhtml: <li id="s<%= supplier.id %>"><%= h(supplier.display_name) %></li> app/controllers/products_controller.rb: def auto_complete_for_supplier_name name = "%#{params[:supplier][:name].downcase}%" conditions = [] values = [] conditions << ''destroyed_at is null'' conditions << ''supplier = 1'' conditions << ''(company_name LIKE ? OR last_name LIKE ? OR first_name LIKE ?)'' 3.times { values << name } @suppliers = Party.find(:all, :limit => 15, :conditions => [conditions.join('' AND ''), values].flatten.compact, :order => %q(CONCAT_WS('' '', company_name, last_name, first_name))) render :layout => false end As you can see, in my _form, I manually created the auto complete magic that Rails usually does for me. I can''t remember anymore, but I think there was no way for me to send the afterUpdateElement option to the Ajax.Autocompleter. I hope that helps ! François
rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
2005-Sep-26 14:09 UTC
Re: Re: [Rails-spinoffs] Autocomplete - setting a second value?
Hi ! I''m so very sorry. This should have been sent to the rails-spinoff list. Sorry for any duplicate posts. François François Beausoleil said the following on 2005-09-26 10:05:> Michael Roper said the following on 2005-09-26 01:46: >> When you say its in the trunk, is it in the latest 1.5 RC1? > Yes, exactly. You can get the latest version at > http://dev.rubyonrails.com/browser/spinoffs/scriptaculous/