我的高级搜索表单有以下代码。当我针对客户选择单选按钮时,下拉值应填充客户数据。
<div class="container">
<%= form_tag search_index_path, method: :get do %>
<%= radio_button_tag :customer, params[:customer] %><p>Customer</p>
<%= radio_button_tag :supplier, params[:supplier] %><p>Supplier</p>
<% end %>
<%= collection_select(:customer, :customer_number, Customer.all, :id, :state) %>
<%= collection_select(:customer, :customer_number, Customer.all, :id, :city) %>
<%= collection_select(:customer, :customer_number, Customer.all, :id, :name) %>
</div>
<%= submit_tag "Search", name: nil %>
目前我面临 2 个问题 - 1. 我可以同时选择两个单选按钮。当我选择另一个时,应该取消选择一个。如何处理。2.单击单选按钮下拉值应显示在屏幕上。
如何处理这两个?另外,如果有人可以建议一个很好的 jquery 和 ajax 资源来学习。
谢谢穆格达
我已经改变了这样的代码
<div class="container">
<%= form_tag search_index_path, method: :get do %>
<%= radio_button_tag 'user_type', 'customer' %><p>Customer</p>
<%= radio_button_tag 'user_type', 'supplier' %><p>Supplier</p>
<% end %>
<h2>Search Criteria</h2>
<div id="dropdown">
<p>State</p>
<%= collection_select(:customer, :customer_number, Customer.all, :id, :state) %>
<p>City</p>
<%= collection_select(:customer, :customer_number, Customer.all, :id, :city) %>
<p>Name</p>
<%= collection_select(:customer, :customer_number, Customer.all, :id, :name) %>
</div>
<div id="dropdown1">
<p>State</p>
<%= collection_select(:supplier, :supplier_number, Supplier.all, :id, :state) %>
<p>City</p>
<%= collection_select(:supplier, :supplier_number, Supplier.all, :id, :city) %>
<p>Name</p>
<%= collection_select(:supplier, :supplier_number, Supplier.all, :id, :name) %>
</div>
</div>
<%= submit_tag "Search", name: nil %>
<script>
$(document).ready(function() {
$("#dropdown").hide();
$("#dropdown1").hide();
$("input[type='radio'][name='user_type'][value='customer']").click(function(){
$("#dropdown1").hide();
$("#dropdown").show();
$("input[type='radio'][name='user_type'][value='supplier']").click(function(){
$("#dropdown").hide();
$("#dropdown1").show();
});
});
});
</script>
现在我必须将下拉列表的选定值和选定的单选按钮传递给控制器,以便我可以从模型中找到符合搜索条件的值。我的问题是如何将 jquery 选择的值传输到控制器?