8

I am using jQuery steps ( https://github.com/rstaib/jquery-steps/wiki ) in order to create step by step form to users to fill out. It works great, however I need to be able to reset it. Once user submitted the form (using ajax so the page doesn't refresh), I would like present a user fresh wizard.

Is there a way to reset the wizard? Or perhaps to reload without reloading the page?

MeIr
  • 7,044
  • 6
  • 40
  • 70

5 Answers5

7

I was able to reset my jQuery steps wizard by adding a few lines of code to the solution here, plus a couple extra lines of code to remove the css classes. You'll still need to reset your form using your preferred library before or after calling this function.

$.fn.steps.reset = function () {
  var wizard = this,
  options = getOptions(this),
  state = getState(this);
  goToStep(wizard, options, state, 0);

  for (i = 1; i < state.stepCount; i++) {
    var stepAnchor = getStepAnchor(wizard, i);
    stepAnchor.parent().removeClass("done")._enableAria(false);
  }
};
atdepott
  • 139
  • 1
  • 6
3

a small correction with the custom reset function :

$.fn.steps.reset = function () {
var wizard = this,
options = getOptions(this),
state = getState(this);

if(state.currentIndex>0)
{
    goToStep(wizard, options, state, 0);   

    for (i = 1; i < state.stepCount; i++) {
    var stepAnchor = getStepAnchor(wizard, i);
    stepAnchor.parent().removeClass("done")._enableAria(false);
    }
}
};

I added a if, in case you try to reset at step 0.

Camille Muller
  • 161
  • 1
  • 7
1

You can use jQuery Form Plugin , Resetting or clearing your form is then very Easy

$('#myFormId').resetForm();

Or

$('#myFormId').clearForm();

Or only Special Fields

$('#myFormId .specialFields').clearFields();
Bunkerbuster
  • 841
  • 9
  • 14
  • jQuery Steps - is a wizard UI with steps and multiple forms. I need to reset entire Wizard not just a single form. PS: Currently I am going exactly what you suggested BUT I want to reset entire Wizard not just form. – MeIr Apr 22 '14 at 19:35
  • Melr, Because you are using the step plugin + form(s), you will have to reset your webapp in two steps. First step reset you webform(s) -> you can use the from plugin for that. Second you need to reset you step webapp. ASardar has a nice solution [Reset steps index when form onFinished](https://github.com/rstaib/jquery-steps/issues/26). – Bunkerbuster Apr 24 '14 at 06:41
  • Currently I am going exactly what you have suggested. However it doesn't completely reset "steps" plugin: tabs are still highlighted and more. – MeIr Apr 24 '14 at 12:49
0
You can user this function after submitting your form:

function resetForm(id_form){
    $("#" + id_form).find('input[type="text"]').val('');
    $("#" + id_form).find('input[type="password"]').val('');
    $("#" + id_form).find('input[type="checkbox"]').removeAttr("checked");
    $("#" + id_form).find('select option').removeAttr("selected");
    $("#" + id_form).find('textarea').val('');
}

Best regards!
Borza Adrian
  • 490
  • 2
  • 12
  • jQuery Steps - is a wizard UI with steps and multiple forms. I need to reset entire Wizard not just a single form. PS: Currently I am going exactly what you suggested BUT I want to reset entire Wizard not just form. – MeIr Apr 22 '14 at 19:36
0

You can paste this:

$.fn.steps.reset = function () {
  var wizard = this,
  options = getOptions(this),
  state = getState(this);
  goToStep(wizard, options, state, 0);

  for (i = 1; i < state.stepCount; i++) {
    var stepAnchor = getStepAnchor(wizard, i);
    stepAnchor.parent().removeClass("done")._enableAria(false);
  }
};

in the jquery.steps.js file right after this code:

$.fn.steps = function (method)
{
    if ($.fn.steps[method])
    {
        return $.fn.steps[method].apply(this, Array.prototype.slice.call(arguments, 1));
    }
    else if (typeof method === "object" || !method)
    {
        return initialize.apply(this, arguments);
    }
    else
    {
        $.error("Method " + method + " does not exist on jQuery.steps");
    }
};

and call it like this wherever you want: $('myjquerystepmodal').steps("reset");

Junaid Ahmad
  • 582
  • 1
  • 4
  • 15