Rails 3 Collection 选择 onchange 提交
当集合选择的值发生更改时,我尝试提交远程表单。我已经尝试过:
"<%= form_tag ( { :controller => :images, :action => :index, :method => "post" }) do %>"
"<%= collection_select(:admin_image, :category_id, Admin::Category.all, :id, :name, {:onchange => remote_function(:url => {:controller => "/admin/admin_home", :action => "index"}, :with => "'category_id='+value")}) %>"
"<% end %>"
但我知道remote_function不再出现在rails 3中。所以我也尝试过:
{:onchange => "submit();"
但是什么也没有发生。
I'm trying to submit a remote form when the value of a Collection Select changes. I've tried:
"<%= form_tag ( { :controller => :images, :action => :index, :method => "post" }) do %>"
"<%= collection_select(:admin_image, :category_id, Admin::Category.all, :id, :name, {:onchange => remote_function(:url => {:controller => "/admin/admin_home", :action => "index"}, :with => "'category_id='+value")}) %>"
"<% end %>"
But I understand that remote_function is no longer in rails 3. So I've also tried:
{:onchange => "submit();"
But nothing happens.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为此,您需要使用 Javacsript。如果您使用 jQuery,那就很简单。您需要侦听“更改”事件并在其触发时提交表单。我使用这个通用函数,然后使用“submit_on_change”类标记我想要在更改时自动提交的表单:
确保在 dom 加载后运行此函数,例如在文档准备好时。
You'll need to use Javacsript for this. If you're using jQuery, it's simple. You'll want to listen for the 'change' event and submit the form when it fires. I use this generic function and then tag forms I want to auto-submit on change with the "submit_on_change" class:
Make sure you run this after the dom loads, for example on document ready.
经过网上搜索,我找到了更好的解决方案。希望有帮助....
"/admin/images", :action => "index" }) do %>
"submit();" %>
After searching on the web, I found a better solution. Hope it helps....
"/admin/images", :action => "index" }) do %>
"submit();" %>