Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Form Reset causes "out of stack space" error with jquery.validation

I have a form that (in it's simplest form) is like the following:

<!DOCTYPE html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!-->
<html class="no-js">
<!--<![endif]-->
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <title>PC Trade Up - Test </title>
</head>
<body id="tech">
    <div id="page">
        <section id="main">
            <h2>
            Test
            </h2>
            <form action="/tech/migration/test" method="post">
                <input id="test1" name="test1" type="text" value="" />    
                <div>
                    <button type="Submit" id="formSubmit" class="btn">
                        Submit
                    </button>
                    <button type="Reset" id="formReset" class="btn">
                        Reset
                    </button>
                </div>
            </form>
        </section>
    </div>
    <script src="/Scripts/jquery-1.9.1.js"></script>
    <script src="/Scripts/jquery.validate.js"></script>
    <script src="/Scripts/jquery.validate.unobtrusive.js"></script>
    <script src="/content/js/lib/jquery.form.js"></script>
</body>
</html>

I can use this form and submit with no issues. When I hit the Reset button however I receive "SCRIPT28: Out of stack space" in the IE10 console. Oddly perhaps, I cannot reproduce this in Firefox.

I've avoided the issue by removing the jquery.form.js reference, but this is included in my bundle. The error seems to bubble out of jquery.validation.js. I've traced this to line 417 of this script which reads as follows:

resetForm: function () {
    if ($.fn.resetForm) {
        $(this.currentForm).resetForm();
    }
    this.submitted = {};
    this.lastElement = null;
    this.prepareForm();
    this.hideErrors();
    this.elements().removeClass(this.settings.errorClass).removeData("previousValue");
},

The line

$(this.currentForm).resetForm();

seems to call recursively for 254 iterations before producing this error, (makes sense). But I cannot determine the source of the recursion. I understand that triggering an event on a descendant will bubble and cause this kind of loop, but I do not see where I am doing this, nor do I see this in this script.

Any suggestions for determining the source of the recursion or loop?

like image 946
Kerry Avatar asked Jan 10 '14 19:01

Kerry


1 Answers

I faced the same problem and I am able to solve it by commenting out the aforesaid function:

    resetForm: function() {
        if ( $.fn.resetForm ) {
            //$(this.currentForm).resetForm();
        }
        this.submitted = {};
        this.lastElement = null;
        this.prepareForm();
        this.hideErrors();
        this.elements().removeClass( this.settings.errorClass ).removeData( "previousValue" );
    },

I know there should be some proper implementation but this patch solves problem as of now, I tried in FF & Chrome too and it seems to be working properly.

like image 183
Dharmang Avatar answered Oct 15 '22 21:10

Dharmang