François Beausoleil
2005-Sep-26 10:32 UTC
[Fwd: [Rails] Re: [Rails-spinoffs] Autocomplete - setting a second value?]
Yeah, right... I posted this to the Rails mailing list. Sorry for people who see duplicate posts. -------- Original Message -------- Subject: [Rails] Re: [Rails-spinoffs] Autocomplete - setting a second value? Date: Mon, 26 Sep 2005 10:05:24 -0400 From: Fran?ois Beausoleil <fbeausoleil@ftml.net> Reply-To: rails@lists.rubyonrails.org To: rails@lists.rubyonrails.org References: <9e765b7cd8a317c86b17016087a2876e@worldwide.com.au> <433308FB.70606@gmx.net> <36ee05af54b19aa004dd668799094b15@worldwide.com.au> <43340DEE.7080904@ftml.net> <52E161AB-3747-41A6-A20F-FB1D41FAAE09@worldwide.com.au> 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 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 mailing list Rails@lists.rubyonrails.org lists.rubyonrails.org/mailman/listinfo/rails -- Fran?ois Beausoleil Solutions Technologiques Internationales T?l?phone: (819) 566-5997 Courriel: francois@teksol.info
Michael Roper
2005-Sep-26 12:43 UTC
[Fwd: [Rails] Re: [Rails-spinoffs] Autocomplete - setting a second value?]
That''s exactly what I was looking for! Thanks a heap Fran?ois... On 26/09/2005, at 10:08 PM, Fran?ois Beausoleil wrote:> {afterUpdateElement: function(element, selectedElement) { > $(''product_supplier_id'').value > selectedElement.id.substring(1);}}