I'm developing a project on rails and I got a problem on getting the selected item on drop down menu. It works fine on views/applications but when I try to use the same code to get the selected item at the jQuery model dialog box, it doesn't work for me. Can someone explain the problem in this? Can't I use the observe_field on model dialog box?
我正在rails上开发一个项目,在获取下拉菜单上的选定项时遇到了一个问题。它在视图/应用程序上工作得很好,但是当我试图使用相同的代码在jQuery模型对话框中获取所选项时,它对我不起作用。有人能解释一下这个问题吗?我不能在模型对话框中使用observe_field吗?
This is my code:
这是我的代码:
<%= label_tag :Search_by %>
<select name="search" id="search" >
<option value="0">Name</option>
<option value="1">Trainer</option>
<option value="2">Venue</option>
<option value="3">Date</option>
</select>
<div id="div_to_be_updated" style="float:right">
<%= render 'layouts/new_search' %>
</div>
<%= observe_field 'search', :update => 'div_to_be_updated',
:url => {:controller => 'events', :action=> 'find' },
:with => "'is_delivery_address=' + escape(value)" %>
</div>
This is my "find" method in "events" controller:
这是我在“事件”控制器中的“查找”方法:
enter code here
def find
@trainers= Trainer.all
@countries= Country.all
if ["0"].include?(params[:is_delivery_address])
render :partial => 'layouts/new_search'
else if ["2"].include?(params[:is_delivery_address])
render :partial => 'layouts/venu_search'
else if ["1"].include?(params[:is_delivery_address])
render :partial => 'layouts/trainer_search'
else
# check element is date range...
render :partial => 'layouts/date_search'
end
end
end
end
I can't understand the reason for this problem. It works in application.html.erb file but it doesn't work on the jQuery model dialog box.
我不理解这个问题的原因。它在application.html工作。erb文件,但是它不能在jQuery模型对话框中工作。
1 个解决方案
#1
3
I see here that RoR uses Prototype to create 'observable' element in form. If this happens before you create your jQuery modal dialog box (i guess again you use jQuery UI Dialog) it could 'observe' wrong or non existing element.
我在这里看到RoR使用Prototype创建“可观察”元素的形式。如果在创建jQuery模态对话框(我猜您也使用了jQuery UI对话框)之前发生这种情况,它可能会“观察”错误或不存在的元素。
Try creating dialog before observable ergo before RoRs PrototypeHelpers run.
在RoRs原型机运行之前尝试创建对话框。
#1
3
I see here that RoR uses Prototype to create 'observable' element in form. If this happens before you create your jQuery modal dialog box (i guess again you use jQuery UI Dialog) it could 'observe' wrong or non existing element.
我在这里看到RoR使用Prototype创建“可观察”元素的形式。如果在创建jQuery模态对话框(我猜您也使用了jQuery UI对话框)之前发生这种情况,它可能会“观察”错误或不存在的元素。
Try creating dialog before observable ergo before RoRs PrototypeHelpers run.
在RoRs原型机运行之前尝试创建对话框。