Search code examples
javascriptjqueryparsley.jsparsley

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';
elem.removeError(error_name);
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 method.

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

 elem.removeError(error_name);

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 undefined

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


Solution

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

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