3

I am using jquery smartwizard My wizard opens in a dialog when a user clicks on a button named "create". When the user clicks the button again, I want the wizard to reset and start a fresh wizard but it retains its state. If i reinitialize it, then it adds the next, previous and finish buttons again and messes the entire wizard UI. Any ideas how I can reset the smart wizard?

slashnick
  • 26,167
  • 10
  • 55
  • 67
vivek jain
  • 31
  • 1
  • 4
  • 1
    If my answer solved your issue (or any other for that matter) please mark the answer by clicking the checkmark. This is how Stack Overflow works so that future visitors will be helped. – lucuma Jun 13 '12 at 01:29

3 Answers3

6

Wizard reset public method is included in the latest Smart Wizard 4, see the example.

$('#smartwizard').smartWizard("reset"); 

Calling this function will reset the wizard to the initial default state.

Dipu Raj
  • 1,784
  • 4
  • 29
  • 37
3

Depending on which dialog you are using, I think what you will need to do is the following:

  1. Create a template for your wizard element that is hidden
  2. When you open the dialog (onOpen), clone the element and apply the smartwizard
  3. When the dialog is closed, remove the element that you've cloned.

Here is a demo using colorbox:

http://jsfiddle.net/lucuma/Kn2ud/4/

Edit: Since the fiddle is no longer working due to the movement of libraries from when it was created, the code is below:

 $("button").colorbox({
            inline: true,
            open: true,
            width: "1000px",
            href: '.inline',
            onClosed: function() {
                $('.inline .swMain').remove();
            },
            onOpen: function() {
                $('.template').clone().removeClass('template').appendTo('.inline').smartWizard({
                    transitionEffect: 'slideleft',
                    onFinish: onFinishCallback
                });
            }
        });
lucuma
  • 18,247
  • 4
  • 66
  • 91
  • i am also doing same thing but i don't want smartwizard to retain the information, i want it to reinitialize its state, i.e. it should always show the first page whenever the button is clicked (i can force that by using goto but there maybe other state variables, e.g. completed pages etc. ) how can i have smartwizard forget/reset its state? – vivek jain Jun 12 '12 at 22:27
  • @vivekjain I've updated the answer. Since the smartwizard plugin doesn't have a destroy event/function we can remove when we hide the dialog. – lucuma Jun 12 '12 at 22:42
  • although the markup that comes up in my dialog is pretty huge but this will work, only thing is that, what will happen to the ids of the elements? will they be duplicated. At many places i am using $("#id") to access an element, will that code break? – vivek jain Jun 13 '12 at 13:54
  • It should be fine. Make sure the template does NOT have an id and when you clone you can apply the id like this: `$('.template').clone().removeClass('template').attr('id', 'myid').appendTo('.inline').....` Updated fiddle: http://jsfiddle.net/lucuma/Kn2ud/5/ – lucuma Jun 13 '12 at 14:02
  • as i said my markup is big, it will be impractical to set id of each element this way. – vivek jain Jun 13 '12 at 15:14
  • Although the html markup isn't valid you can still do things like `$('.inline #id')` as long as you don't reference it like `$('#id')` which may cause an issue. Give it a try. – lucuma Jun 13 '12 at 16:57
  • thanks lucuma but that doesn't help me, i am now loading the markup from server, not efficient but reliable and stable. – vivek jain Jun 13 '12 at 19:44
  • @lucuma, I'm surprised no one else has upvoted your answer. Thanks! – Casey Flynn Aug 01 '12 at 07:19
  • I appreciate the upvote. Of course it would have been helpful for the OP to have marked the answer but that's a lot to ask for sometimes. – lucuma Aug 01 '12 at 11:32
1

This seems to work for me (in coffeescript, but you get the idea).

numSteps = 5
wizardDiv.smartWizard('goToStep', 1)
# disable all the following steps
for i in [2..numSteps]
    wizardDiv.smartWizard('disableStep', i)

Clearing out or retaining any data in the wizard itself is up to you.

voodoogiant
  • 2,118
  • 6
  • 29
  • 49