Forum: Ruby on Rails Customizing autocomplete to update more than one value upon

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
D2eecb3df7da359aa6f6559fddc39945?d=identicon&s=25 Damon Hill (Guest)
on 2006-01-10 16:50
(Received via mailing list)
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"}
  Product Load (0.078000)   SELECT * FROM products
WHERE
(product_code LIKE '%5%') 
  Product 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_comple...
]


The result after a product code is chosen is nothing.
Nothing happens in the view and nothing happens in the log file.

Thoughts?
~damon
This topic is locked and can not be replied to.