Damon Hill
2006-Jan-10 15:26 UTC
[Rails] Customizing autocomplete to update more than one value upon vaule select
Good day. Currently I have a system that will successfully add a row to a table. Each row in this table will represent a new product being added to a purchase order. The user can enter a quantity and then select a product code. The product code is the auto_complete field. This field works. However, once the user selects a product code then the values for the product description, buy price, and unit weight should be updated automatically. To try and achieve this I have implemented the following: view: <td rowspan="2" align="center"><%= text_field_with_auto_complete( :product, :product_code, {}, { :updateElement => ''function(selectedElement){ alert("Element Selected: " + selectedElement.id);}'' }) %></td> <td rowspan="2" align="center"><input type="text" id="description_#{@counter}" size="40"></td> <td align="center"><input type="text" id="buy_price_#{@counter}" size="10"></td> <td align="center"><input type="text" id="sell_price_#{@counter}" size="10"></td> </tr> <tr> <td align="center"><input type="text" id="weight2_#{@counter}" size="10"></td> controller: def auto_complete_for_product_product_code auto_complete_responder_for_products params[:product][:product_code] end ... private def auto_complete_responder_for_products(value) @products = Product.find(:all, :conditions => [''product_code LIKE ?'', ''%'' + params[:product][:product_code] + ''%''] ) render :partial => ''podetails_product'' end partial: <ul> <% for @product in @products do %> <li weight="<%= @product.unit_weight %>" buy_price="<%= @ product.unit_price %>" description="<%= @product.product_name %>"><%= @ product.product_code %></li> <% end %> </ul> The log shows the following when attempting to enter a product code: Processing PurchaseOrderDetailController#auto_complete_for_product_product_code (for 127.0.0.1 at 2006-01-10 09:19:52) [POST] Parameters: {"product"=>{"product_code"=>"5"}, "action"=>"auto_complete_for_product_product_code", "controller"=>"purchase_order_detail"} [4;36;1mProduct Load (0.078000) [0;1mSELECT * FROM products WHERE (product_code LIKE ''%5%'') [4;35;1mProduct Columns (0.000000) SHOW FIELDS FROM products Rendered purchase_order_detail/_podetails_product (0.12500) Completed in 0.28100 (3 reqs/sec) | Rendering: 0.12500 (44%) | DB: 0.07800(27%) | 200 OK [ http://localhost/purchase_order_detail/auto_complete_for_product_product_code ] The result after a product code is chosen is nothing. Nothing happens in the view and nothing happens in the log file. Thoughts? ~damon -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060110/96a97c1f/attachment.html