amoffat / bootstrap-application-wizard

MIT License
1.85k stars 388 forks source link

Is there a way to upload files included in wizards #56

Open lgt opened 10 years ago

lgt commented 10 years ago

I try to upload files but doesn't seems to work or in my case I don't know what is the workaround.

wizard.on("submit", function(wizard) {

        var formData = new FormData($('form:file'));
        alert(); //no alert
        console.log(formData); //no logs

    });
jogaco commented 10 years ago

I liked the wizard but didn't need the modal features, so I used it with a standard submit. One of my steps has a file upload. I tweaked the implementation like this. Might not be the best one but worked:

var wizard = $('#my-wizard').wizard({ showCancel: true, progressBarCurrent: true });
wizard._defaultSubmit = function(wizard) {
  $('form').submit();
};
wizard.on("submit", wizard._defaultSubmit);
lgt commented 10 years ago

thank you for the feedback!! Actually what you suggest to override the default wizzard submit and is good like, however I was trying the following as you suggested

 wizard._defaultSubmit = function(wizard) {
            jQuery('form').submit(function( event ) {
                alert( "test submit" );
                event.preventDefault();
            });
        };

        wizard.on("submit", wizard._defaultSubmit);

and I expect to get an alert but is not happening. No errors in firebug are reported

jogaco commented 10 years ago

You need to enclose your wizard within form tags with the corresponding url. It should work. For instance, bearing in mind you want to upload files:

<form method="post" id="myform" enctype="multipart/form-data" action="/myaction">
   your wizard markup here
</form>

Let me know.

lgt commented 10 years ago

thanks again for your feedback. The wizzard has a form tag already this one should be changed? Is there a way to upload files via ajax on form submit?

jogaco commented 10 years ago

I did comment out the

<form> 

tags in the bootstrap-wizard.js template code. Try it. As you need to do file upload your form must include the multipart encoding. As for ajax file upload, that's a different beast. I didn't need it so I opted for a simpler solution.

lgt commented 10 years ago

okay let me give a try this issue hangs on my neck almost for 1 week and thanks again for your nice feedback

jogaco commented 10 years ago

I'd recommend you too to use bootstrap-fileupload.js from https://github.com/jasny/bootstrap/releases/tag/v2.3.0-p4 as it replaces the ugly file upload button with a nice bootstrap styled button, and offer the possibility of image preview in some browsers as well.

lgt commented 10 years ago

I made a switch from jasny to blueimp and I try now to use it for multiple file uploads with other form elements.