Bootstrap Modal Form Fix

Results 1 to 1 of 1
  1. #1
    Web Developer Markshall is offline
    MemberRank
    Oct 2009 Join Date
    EnglandLocation
    628Posts

    Bootstrap Modal Form Fix

    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 Code:
    $("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
    Last edited by Markshall; 17-12-12 at 06:58 PM.




Advertisement