开发者

Why working observe_field code doesn't work with JQuery Model dialog box?

开发者 https://www.devze.com 2023-04-11 15:38 出处:网络
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

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?

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.


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.

Try creating dialog before observable ergo before RoRs PrototypeHelpers run.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号