mgildea / Multi-Step-Form-Js

Multi Step Form with jQuery validation
MIT License
49 stars 25 forks source link

AJAX submit #23

Closed pvernaglia closed 4 years ago

pvernaglia commented 4 years ago

Hi, I'm trying to submit a form with ajax after validation, I've tried doing this:

$(".msf:first").multiStepForm({ activeIndex : 0, allowClickNavigation : true,
allowUnvalidatedStep : false,
hideBackButton : false, validate : { submitHandler: function(form) { jQuery.ajax({ url: form.action, data: $(form).serialize(), type: form.method, success: function(response) { $('.results').replaceWith(response); } }); return false; } }
});

But it doesn't appear that submitHandler is doing anything. Is this correct way to implement this or does anyone have an example how to use this with ajax calls. thanks

lvmajor commented 4 years ago

@pvernaglia please try to format the code so it's more easily readable if you want people to try and help you out :)

You can surround the code with triple backticks and it will format it in a pretty code block (also you can specify the language for colorization).

$(".msf:first").multiStepForm({
  activeIndex: 0,
  allowClickNavigation: true,
  allowUnvalidatedStep: false,
  hideBackButton: false,
  validate: {
    submitHandler: function (form) {
      jQuery.ajax({
        url: form.action,
        data: $(form).serialize(),
        type: form.method,
        success: function (response) {
          $('.results').replaceWith(response);
        }
      });
      return false;
    }
  }
});

As for the submitHandler, I tried finding where the problem was and found out that the actual version of this library does not seem to use this setting anymore. It was removed here where a function was created to avoid code duplication and validate specific views.

As to why it was removed, I can't tell for sure at the moment, maybe @mgildea could lighten us up on this one :)