amoffat / bootstrap-application-wizard

MIT License
1.85k stars 388 forks source link

Wizard content not visible after closing and opening #39

Closed ghost closed 11 years ago

ghost commented 11 years ago

Hi,

I want to open a wizard based on which button is pressed. So, i have used the following code:

$(".button").on('click',function(){ var id= $(this).data('btnid'); $("#wizard"+id).wizard().show(); });

But when i click on button -> close modal -> reopen the modal, the wizard content disappears, it just shows an empty wizard.

ghost commented 11 years ago

I figured out the problem. The plugin is trying to create a new wizard and show it. But i'm unable to resolve it.

gjrtimmer commented 11 years ago

@rajprince

To resolve this, first initialize all wizards, and save them in variable.

var wizard_32 = $("#wizard_32").wizard({
    show: false
});

On your click event you them only have to do refer to the variable.

$(".button").on("click", function() {
    var id = $(this).data("btnid");
    switch (id) {
        case 32:
            wizard_32.show();
            break;
    }
});

I hope you understand what I'm trying to show here.

Hope this helps you in the right direction.

SeoRoman commented 10 years ago

I'm doing the exact same thing, but again the issue is the re-initilalizing of the wizard component, but it seems illogical to load 100+ wizard forms if you are only going to use 1 or 2 of them on a page...

\ EDIT **

here is how I fixed the issue...

<script>
    $(function() {

        var wizards = [];
        var options = {
            keyboard : false,
            contentHeight : 400,
            contentWidth : 700,
            backdrop: 'static'
        };            

        $.each($('.wizard'), function(index, value) {
            wizard = $(value);
            wizards[wizard.attr('id')] = wizard.wizard(options);
        });

        $.fn.wizard.logging = true;

        $('a[data-wizard-id]').on('click',function(e) {
            e.preventDefault();

            var form = $(this).data('wizard-id');
            wizards[form].show();                
        });

    });
</script>

This way, all wizards will be loaded when the page loads (for that page) and pushed into the wizards array... Then, you can reference each wizard by the 'id' which is now the array key index of that initialized wizard.