1

JSFiddle: https://jsfiddle.net/fho6m3cr/33/

I'm using jQuery Validation without a Submit button -- instead there's a regular button that invokes $('#form).valid().

I populate my initial fieldset in document.onReady and then 1 more dynamic field after you click the Add button. The Add button receives its rule but never gets picked up and skips validation.

I initialize as

// First initialize jQuery Validation
$("#form").validate({});
// Add first-level validators
$("#form select, #form input:not(input[type=button], input[type=submit], input[type=hidden])").each(function(){
           $(this).rules("add", { required: true } );
});   

and then Add is supposed to handle the new field by adding the same Select/Input validation when it's clicked.

// (Re-)append validator
  $("#form select, #form input:not(input[type=button], input[type=submit], input[type=hidden])").each(function(){
       $(this).rules("add", { required: true } );
});

But it's not working: the newly-added field doesn't get validated. The original one does. The structure of the Form and subsequent DIV is correct.

NOTE There is only 1 possible click of the Add button -- no unique IDs anywhere.

9
  • 1
    You can't repeat ID's in a page...they are unique by definition. Also simpler to just add required attribute Commented Jan 23, 2018 at 18:01
  • But which IDs are repeated? There is only one #form. The text fields' IDs are different. You can check the JSFiddle's layout in Dev Tools. Commented Jan 23, 2018 at 18:05
  • In your add you have hard coded ID's Commented Jan 23, 2018 at 18:08
  • I have hard-coded the ID id="textAdded" which is different from the ID id="text1". They are quite different. Commented Jan 23, 2018 at 18:15
  • 2
    Yep... I looked at your jsFiddle... you have not created any name attributes. The plugin needs them. Read first sentence here: jqueryvalidation.org/reference/#link-markup-recommendations Commented Jan 23, 2018 at 19:05

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.