开发者

Rails pass ID from auto_complete field to observe_field

开发者 https://www.devze.com 2022-12-12 19:42 出处:网络
<p>Song Name:<%= text_field :songlists, :song_name, :id => \"songlists_\" + section.id.to_s + \"_song_name\" %></p>
<p>Song Name:<%= text_field :songlists, :song_name, :id => "songlists_" + section.id.to_s + "_song_name" %></p>

<%= auto_complete_field "songlists_" + section.id.to_s + "_song_name", :method => :get,
        :with => "'search=' + element.value", :url => formatted_songlists_path(:js)  %>

<p>Artist:<%= text_field :songlists, :artist, :id => "songlists_" + section.id.to_s + "_artist" %></p>

<%= observe_field  ("songlists_" + section.id.to_s + "_song_name", :update => "songlists_" + section.id.to_s + "_artist", :with => "element.value" , :url => { :controller => :songlists, :action => "get_artist"  } ) %>

I have the auto-complete-field working fine, and the observe-field is triggering according to firebug, but I开发者_如何学C'm unsure how to update the text-field from the observe-field.

I either need to get the ID that the auto-complete finds, or even the text entered so that I can pass it into the :url of the observe-field.

Any ideas?


Can you walkthrough what you want this code to do?


I'm trying to get the response from the auto-complete field, to update another text-field with the results. I have the responses working now in firebug, but I can't seem to get it to update the box with the results.

<p>Song Name:<%= text_field :songlists, :song_name, :id =>
"songlists_" + section.id.to_s + "_song_name" %></p>


<%= auto_complete_field "songlists_" + section.id.to_s +
"_song_name",      :method => :get,
                   :with => "'search=' + element.value", 
                   :url => formatted_songlists_path(:js)  %>

<p>Artist:<%= text_field :songlists, :artist %></p>

<%= observe_field  "songlists_" +section.id.to_s + "_song_name",
                   :frequency => 0.5, 
                   :url => { :controller => :songlists, 
                   :action => :get_artist }, 
                   :update => "songlists_artist", 
                   :with => "song_name" %>

controller code

def get_artist
@songlist = Songlist.find(:all, :conditions => ['name = ?', params[:song_name]])

if !@songlist.empty?

  render :update do |page|
    page.replace_html 'songlists_artist', :partial =>
    'get_artist', :object => @songlist
 end

end

end

In firebug I see this response

try {
Element.update("songlists_artist", "Robbie Williams");
} catch (e) { alert('RJS error:\n\n' + e.toString());
alert('Element.update(\"songlists_artist\", \"Robbie Williams\");');
throw e }

But it is not updating my text-field, any ideas?

0

精彩评论

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

关注公众号