简体   繁体   English

页面重新加载不要求重新提交表单

[英]Page reload is not asking for form resubmit

I have my application running Ruby on Rails 6. Like any other application, I have some forms too.我的应用程序运行 Ruby on Rails 6。像任何其他应用程序一样,我也有一些表单。 When I submit the form with any error, the URL gets replaced with form action and now when I reload the page I get route error -当我提交有任何错误的表单时,URL 被表单操作替换,现在当我重新加载页面时,我收到路由错误 -
No route matches [GET] "/admins/password"没有路由匹配 [GET] "/admins/password"
Usually when we reload page after form submit with errors, The browser asks if we want to resubmit the form.通常当我们在表单提交出错后重新加载页面时,浏览器会询问我们是否要重新提交表单。 But in my case this is not happening.但就我而言,这不会发生。 This is a basic stuff but no idea what is going wrong.这是一个基本的东西,但不知道出了什么问题。

try to insert event.preventDefault() on your onsubmit event handler function.尝试在onsubmit事件处理函数中插入event.preventDefault() If you post some code would be helpful.如果您发布一些代码会有所帮助。

Easy code would be:简单的代码是:

document.querySelector("#myform").onsubmit = function(event){

 // ...check for errors

  if(errors){
     event.preventDefault();
  }
}

This is what I found really helpful regarding my question.这是我发现对我的问题非常有帮助的。 https://github.com/turbolinks/turbolinks/issues/60 https://github.com/turbolinks/turbolinks/issues/60

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM