Question

Related fiddle:

http://jsfiddle.net/v86Dv/4/

The "First Name" field is validated as expected when the "submit" button is clicked.

But, fields added via the "click here to add field" link are not validated.

How can I get parsely.js (http://parsleyjs.org) to validate those fields?

Related code from fiddle:

HTML:

<form id="myForm" method="post" data-parsley-validate novalidate>
    <p><a href="javascript:void(0)" id="addField">Click here to add field</a></p>
    <p><label>First Name</label>
    <input type="text" name="firstName" value="" required data-parsley-trigger="change" /></p>
    <p><input type="submit" value="submit" /></p>
</form>

JavaScript

$('#addField').on('click', function(){
    $('input[type="submit"]').before('<p><label>Another Field</label> <input type="text" name="anotherField" value="" required data-parsley-trigger="change" /></p>');
});
Was it helpful?

Solution

I'm afraid in your fiddle you are using 1.2.3 Parsley version, that does not support natively dynamic field adding / removing. Please consider using 2.x version. Best

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top