I have the following custom validator. The intended purpose is to validate the field contingent upon the value of the field passed in as 'requirement'.
The 'requirement' field updates onchange of the FieldToBeValidated. In order to prevent the FieldToBeValidated from being invalidated constanly, keyup is turned off.
Once the 'requirement' field is changed, the FieldToBeValidated is not validated until the form is submitted. Consequently the field remains red with the warning box that parsley applies.
How can I change the 'FieldToBeValidated' back to a valid state (removing the red background) after the 'requirement' field updates to be not null or '----'?
name: 'customvalidatorname',
fn: function(value, requirement) {
var nodeList = document.getElementsByName(requirement);
var nodeArray = [].slice.call(nodeList);
$('#FieldToBeValidated').off('keyup');
if(!nodeArray[0].value || nodeArray[0].value === '----'){
return false;
}
return true;
},
window.ParsleyUI.removeError($("input[name=fieldName]").parsley(), 'required');
(see docs). If you want to remove the validation from that field altogether check this answer. – Duxwindow.ParsleyUI.removeError($("input[name=fieldName]").parsley(), 'required');
does remove the error message, but leaves the parsley-error. However, thanks to your link I was able to find$('#FieldToBeValidated').parsley().reset();
which resolved the issue, by reseting the parsley status on the field. If you answer the question including this solution in an example I will accept the answer. Thanks! – Euphonium