简体   繁体   中英

skipping client side validations

i have just finished watchin Ryan Bates RailsCast on multi steps form. 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. 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:

= 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 %>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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