将 Decendant 复选框的两个参数与父 input_field 关联 [英] Hold both params of Decendant checkbox accociate with parent input_field
问题描述
有一个 select_tag
来选择客户.当用户选择一个客户时,它会在 select_tag
下方生成一个子 checkbox_from.
There is a select_tag
to select the customer. When user selected a customer, it will generate a child checkbox_from below the select_tag
.
用户可以选择一个客户并选中两个或仅一个客户的后代复选框.
User can select a customer and check the decendant checkbox both or either only customer.
如果用户只选择一个客户然后搜索,它会得到结果,刷新后select_tag
值(param)也保存在select标签中.
If user select only a customer then searched,It will get the results and select_tag
value(param) also hold in the select tag after the refresh.
但问题是,如果我尝试同时获取 select_tag
和 checkbox_tag
数据,它将生成数据但两个参数都消失了.我需要在搜索结果后保留这两个参数.
But the problem is if I try get the both select_tag
and checkbox_tag
data, it will generate the data but both params are gone. I need to hold both params after the search results.
这是我的看法
.row
.col-md-3
= label_tag "Customer/Supplier Name"
= select_tag "search_customer_supplier[id]", options_from_collection_for_select(Organization.customers_and_suppliers, :id, :name, params.dig('search_customer_supplier', 'id')), class: "form-control parent_class chosen-select", id: "search_registered_customers", include_blank: true
.col-md-10.small_scale_margin-top2#check_children_wrapper.hide
= label_tag "Descendent"
= check_box_tag "organization_children", "true", params.dig('search_customer_supplier', 'organization_children')&.include?('true')
这是我关于复选框的控制器代码
This is my controller code regarding to the checkbox
def customer_supplier_report
Organization
Address
ContactNumber
refined_query = ""
if params[:search].present? or params[:excel_report].present?
search_customer_supplier = params[:search_customer_supplier]
if params[:organization_children].present? and search_customer_supplier["id"].present?
organization_id = search_customer_supplier["id"]
organization = Organization.find(organization_id)
anchestor_ids = organization.anchestors.map{|o| o[:member].id }
search_customer_supplier["id"] = "(#{anchestor_ids.join(' OR ')})" if anchestor_ids.any?
end
params[:search_customer_supplier]['accounts_dealer_types.dealer_code'] = params[:search_customer_supplier]['accounts_dealer_types.dealer_code'].join(" OR ") if params[:search_customer_supplier]['accounts_dealer_types.dealer_code'].present?
customer_report = params[:search_customer_supplier].map { |k, v| "#{k}:#{v}" if v.present? }.compact
推荐答案
这与您之前的问题相反.
This is the opposite of your previous question.
你的check_box_tag
的参数名是'organization_children'
,所以它会传入params[:organization_children]
.您在控制器中正确访问它,在视图中执行相同操作:
Your check_box_tag
's parameter name is 'organization_children'
, so it will be passed in params[:organization_children]
. You access it correctly in controller, do the same in the view:
= check_box_tag "organization_children", "true", params[:organization_children].present?
这篇关于将 Decendant 复选框的两个参数与父 input_field 关联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!