简体   繁体   English

跳过客户端验证

[英]skipping client side validations

i have just finished watchin Ryan Bates RailsCast on multi steps form. 我刚刚完成了多步表单上的Ryan Bates RailsCast监视。 Its great and all, but as you can see here Ryan is using two submit buttons, one for continue and saving the model, and the other one, "back button" for going back to the previous step. 它的功能非常强大,但是,正如您在此处看到的那样 Ryan使用了两个提交按钮,一个用于继续并保存模型,另一个是“后退按钮”,用于返回上一步。 I have done the same thing and it works perfectly, only when I'm using this "back" client side validation is still on! 我做过同样的事情,并且只有当我使用此“后向”客户端验证仍然有效时,它才能完美运行! And thats kinda silly to tell user to fill all the necessary information before he can go back and maybe fix some mistakes. 告诉用户填写所有必要的信息,然后再返回并修复一些错误,这有点愚蠢。 How can i prevent this kind of behaviour and only allowa client side validation when "continue" button is pressed? 当按下“继续”按钮时,如何防止这种行为并且仅允许客户端验证?

my code is pretty much the same as Ryans but i'm giving it anyway: 我的代码与Ryans几乎相同,但无论如何我都给它:

= simple_form_for @poster do |f|
    = render "#{@poster.current_step}_step", f: f
    = f.submit "Back", name: "back_button" unless @poster.first_step?
    = f.submit "Continue"

You could try linking to back so that it doesn't try to act as a commit (not sure if this would lose your previously entered data though - you'll have to try it). 您可以尝试链接回去,这样它就不会尝试充当提交(尽管不确定这样做是否会丢失您先前输入的数据-您必须尝试一下)。 Like so: 像这样:

<%= link_to "Back", :back %>

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

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