ProgrammedChem ProgrammedChem - 6 months ago 18
jQuery Question

JQuery Validation Date on dynamically created form

I want to validate a form that is dynamically generated. If I enter 123 in the form, it always returns true. Here is the code where I dynamically create the form:

//create dummy form so we can validate
$(".clearfix").append('<form action="#" id="dummyform" method="POST">');
$("#dummyform").append('<input type="text" name="dummyelement" class="date form-control" id="dummyelement"/>');

$('#dummyform').validate({
ignore: [],
rules:{
dummyelement:{
required: true,
date: true

}
}
});


I input 123, then call:

$('#dummyelement').valid()


this always returns true, for any input unless the input is empty. Can anyone elaborate why the date validation is not occuring?

Thanks!!

Answer

Apparently, the jQuery Validate plugin thinks "123" is a valid value for the date rule. Conversely, enter "abc" and it's not valid.

In other words, you are doing nothing wrong, and should report this as a bug to the developer on his GitHub page. Include the jsFiddle below inside your bug report.

DEMO: http://jsfiddle.net/Ls3kqfu6/

BTW, you do not need to use class="date" along with date: true... that is a redundant declaration of the rule.

Comments