I have a form ('#registrations') that I am validating with Parsley.js and so far it is working fine. However, I am trying to dynamically remove form fields and add new ones to Parsley validation, depending on what someone selects in a select drop down ('#manufacturer').
Here is my markup:
<select name="manufacturer" id="manufacturer" parsley-required="true" data-error-message="Please select a manufacturer.">
<option value="apple">Apple</option>
<option value="blackberry">Blackberry</option>
<option value="htc">HTC</option>
<option value="huawei">Huawei</option>
<option value="lg">LG</option>
<option value="motorola">Motorola</option>
<option value="nokia">Nokia</option>
<option value="samsung">Samsung</option>
<option value="sony">Sony</option>
<option value="sony-ericsson">Sony Ericsson</option>
</select>
Here is my JS:
//init parsley
$('#registrations').parsley();
$('#manufacturer').change(function() {
//define selected value
var manufacturer = $(this).val();
//destroy parsley
$('#registrations').parsley('destroy');
//remove all models selects from parsley validation
//if someone has previously selected a different manufacturer
$('#registrations').parsley('removeItem', '#apple-models');
$('#registrations').parsley('removeItem', '#blackberry-models');
$('#registrations').parsley('removeItem', '#htc-models');
$('#registrations').parsley('removeItem', '#huawei-models');
$('#registrations').parsley('removeItem', '#lg-models');
$('#registrations').parsley('removeItem', '#motorola-models');
$('#registrations').parsley('removeItem', '#nokia-models');
$('#registrations').parsley('removeItem', '#samsung-models');
$('#registrations').parsley('removeItem', '#sony-models');
$('#registrations').parsley('removeItem', '#sony-ericsson-models');
//add corresponding models select to parsely
$('#registrations').parsley('addItem', '#'+manufacturer+'-models');
//reinit parsley
$('#registrations').parsley();
});
This isn't working but I don't know why.