2009-12-01 59 views
0
<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" }) %> 

我有自动完成字段工作正常,并且观察字段是根据萤火虫触发,但我不确定如何更新文本字段从观察视野。Rails通过ID从auto_complete字段observe_field

我要么需要获得自动完成发现的ID,要么输入文本以便我可以将它传递到观察字段的URL中。

任何想法?

回答

0

你能走过你想要这个代码做什么?

0

我试图从自动完成字段获取响应,以便用结果更新另一个文本字段。我现在的反应在萤火虫中工作,但我似乎无法得到它与结果更新框。

<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" %> 

控制器代码

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

if [email protected]? 

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

end 

end 

在Firebug我看到这个响应

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 } 

但它没有更新我的文本字段,任何想法?