问题标签 [remote-forms]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
912 浏览

javascript - Rails remote form submitting multiple times with 'enter'

I have a form on a page that is a single input field. I would like the user to be able to hit enter to submit the form. Unfortunately, the form gets submitted multiple times when enter is used to submit. I know the form is being submitted multiple times because there are multiple POST requests sent to the server. It happens in both development and production and it only happens sporadically.

If I add a f.submit to the form, it will only submit once.

This is Rails 5 with turbolinks and jquery_ujs included in the application.js if that makes any difference.

UPDATE

I haven't been able to reproduce after making some changes.

I suspect the issue had to do with jquery_ujs being loaded multiple times on the page. This was due to turbolinks. More precisely, due to the fact that I was including all of my javascript in the body tag. turbolinks suggests adding your javascript files in the head tag. Since doing so, I have not been able to reproduce the error.

0 投票
1 回答
269 浏览

ruby-on-rails - Rails 5.2 - 删除 data-remote 属性不会将表单作为 HTML 请求提交

我在 Rails 5.2.2 中呈现一个搜索表单,并具有确定请求应该是 AJAX 请求还是 HTML 请求的逻辑。这是我的表单的样子:

如果搜索查询data-prev-query与表单上的属性不同,那么我希望表单提交是一个 HTML 请求,以便重新加载页面。否则,我希望表单提交是 AJAX 请求。data-remote这是我以编程方式从表单中删除属性的逻辑:

我已确认此代码data-remote按预期删除或添加了该属性。但是,即使data-remote删除了该属性,表单仍然作为 AJAX 请求提交。

如何让表单作为 HTML 请求提交?顺便说一句,我没有使用 Turbolinks。

0 投票
1 回答
122 浏览

ruby-on-rails - Rails form_for 助手认证参数?

我有一些旧版 Rails 代码指定已验证:对于远程表单为 true。但据我所知,参数什么也没做。也许开发人员想要包含一个真实性令牌?

我进行了搜索,但没有找到有关此参数的文档。

值得一提的是生成的 HTML,但我在其中看不到任何与身份验证相关的内容: