Show DevBest Bootstrap Modal Form Fix

Status
Not open for further replies.

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,638
2,393
You might get the wrong impression by the title of this thread. Forms in Bootstrap's Modal plugin aren't broken so there is nothing to fix, this is just a little code that improves the forms.

For example, you may have a Modal dialog with a form inside of it and the user may edit some of the information in the form and then close the dialog without submitting the form, this means that when the user reopens the dialog, the information won't be in it's truest state and this wasn't good for the project I'm working on at the minute so I spent 2 minutes writing this code to reset all of the forms in each Modal dialog.

PHP:
$("div.modal[role='dialog']").each(function(i,a){
    $(a).on('hidden', function(){
        var allforms = $(this).find('form');
        if (allforms.length > 0) {
            $(allforms).each(function(k,p){
                $(p)[0].reset();
            });
        }
    });
});

This code will mean that when the user reopens the dialog, the information in the form will be in its truest state.

I hope this helped.

- Mark
 

Jian

Resident Weeb
Contributor
Sep 2, 2011
687
437
Thanks man. Just what I was finding a solution for. Helps alot!
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,638
2,393
no worries, glad it helped!
 
Status
Not open for further replies.

Users who are viewing this thread

Top