轨道 3 和Ajax date_select onchange =>;提交

发布于 2024-11-18 10:53:31 字数 252 浏览 9 评论 0原文

我希望每次通过 ajax 更改日期时都能保存我的日期,这可能吗?我尝试了

<%= form_for @dates,:remote => true do |f| %>
    <%= f.date_select :booking_date,:onchange => "this.form.submit();" %>
<% end %>

,但没有任何作用,有什么好的解决方法吗?

I'd like my date to get saved anytime I change my date via ajax, is this possible? I tried

<%= form_for @dates,:remote => true do |f| %>
    <%= f.date_select :booking_date,:onchange => "this.form.submit();" %>
<% end %>

but it does nothing, any good work arounds?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

拔了角的鹿 2024-11-25 10:53:31

来自rails文档:

date_select(object_name, method, options = {}, html_options = {})

因为onchange是一个html选项,所以您需要为date_select提供一组空选项,否则它假设onchange是一个date_select选项。

您应该将对 date_select 的调用更改为如下所示:

f.date_select :booking_date, {}, :onchange => "this.form.submit();"

From the rails documentation:

date_select(object_name, method, options = {}, html_options = {})

Because onchange is an html option you need to provide an empty set of options to date_select, otherwise it assumes onchange is a date_select option.

You should change your call to date_select to look like this:

f.date_select :booking_date, {}, :onchange => "this.form.submit();"
久夏青 2024-11-25 10:53:31

您是否将其包含在您的布局中:

<%= javascript_include_tag :defaults %>
<%= csrf_meta_tag %>

Are you including this in your layout:

<%= javascript_include_tag :defaults %>
<%= csrf_meta_tag %>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文