How can I bind validation using the pattern attribute on an input to an existing bound parsley validator?
Let's say I have a form, which is already initialized, and the user actions something which will push in a diving license field to the form, this field needs patterns on it so that they only enter numbers.
FIELD:
<input id="74" name="DivingLicence" type="text" value="" pattern="\d+" data-parsley-pattern="\d+" data-error-message="The Diving License is not valid" >
Javascript:
var item = {
field : '#74'
}
$('form').parsley('addItem', item.field);
var field = $(item.field);
if ('string' === typeof field.attr('pattern')) {
field.parsley('addConstraint', {
'pattern' : field.attr('pattern')
});
}
This is what I've tried, but I can't seem to raise an error at all when I enter anything wrong....