Edgar Navasardyan Edgar Navasardyan - 2 months ago 30x
jQuery Question

Calling parsley.js method 'addError' on the instance directly

I have the following HTML source (generated by Django template engine):

<input class="form-control input-sm" id="id_kpp" maxlength="45" name="kpp" pattern="^\d{12}$|^\d{10}$" required="" type="text" data-parsley-group="block-0">

When I try to apply this code to the element:

var elem = $('#id_kpp').parsley();
var error_name = 'multiple_inn_kpp';
window.ParsleyUI.addError(elem, error_name, 'My custom error msg');

..I get a warning in Google Chrome stating that

Accessing ParsleyUI is deprecated. Call 'addError' on the instance
directly. Please comment in issue 1073 as to your need to call this

I tried to rewrite the removeError-part the following way and it worked for me.


But if I try to rewrite addError-part in the similar way:

elem.addError(error_name, 'My custom error msg');

I get error message in the Browser:

parsley.js:1000 Uncaught TypeError: Cannot read property 'name' of

The doc is very sketchy on using addError method. Any ideas ?


elem.addError(error_name, {message: 'My custom error msg'});

I've added colons in the doc, hoping that it will be more clear now.