[英]Rails pass ID from auto_complete field to observe_field
<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" } ) %>
我的自動完成字段工作正常,並且觀察字段正在根據螢火蟲觸發,但是我不確定如何從觀察字段更新文本字段。
我要么需要獲取自動完成功能找到的ID,要么甚至要輸入輸入的文本,以便可以將其傳遞給observe-field的:url。
有任何想法嗎?
您可以逐步了解一下此代碼要執行的操作嗎?
我正在嘗試從自動完成字段中獲取響應,以使用結果更新另一個文本字段。 我的響應現在在Firebug中起作用,但是我似乎無法用它來更新結果框。
<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 !@songlist.empty?
render :update do |page|
page.replace_html 'songlists_artist', :partial =>
'get_artist', :object => @songlist
end
end
end
在螢火蟲中,我看到此響應
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 }
但這不是更新我的文本字段嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.