Skip to content Skip to sidebar Skip to footer

Validate Dynamically Generated Form With Jquery Validator

Sorry for keep asking this, but I just can't figure it out. I've reduced the question to just the bare minimum. How can I validate a dynamically generated form? Below is my attem

Solution 1:

  1. The button needs to be inside the form and be a type="submit" in order for the plugin to capture the click.

  2. Do not put .validate() within a click handler (See item 1). It's only used to initialize the plugin on a form. Exception, below we are creating the new form within a click handler and then immediately calling .validate() on the new form.

With these two small changes, the validation on the static form is working: jsfiddle.net/j2pgobze/3/

  1. I rewrote your DOM manipulation code for clarity. I simply duplicated the HTML for the form and gave it a new ID: http://jsfiddle.net/zem84tfp/

$(function () {

     // INITIALIZE plugin on the traditional formvar validate1 = $('#myForm').validate(myValidateObj);

     $('#newform').one('click', function () {

         // code here to create new form; give it new ID// do not duplicate ID on anything else// INITIALIZE plugin on the new formvar validate = $('#myForm2').validate(myValidateObj);
     });

});

Post a Comment for "Validate Dynamically Generated Form With Jquery Validator"