Search code examples
javascriptjqueryparsley.jsparsley

Parsley.UI.addError doesn't get messages disabled


I am using Parsley to validate some forms and the server is doing same validations in his side. When a constraint fail on the server, i call this function do add the error on parsley:

var invalidField = $('[name="' + param.target + '"]').parsley();
window.ParsleyUI.addError(invalidField, "remoteError_"+param.target, param.message);

Param.target is the name of the input field to invalidate. The error shown as li under the field, but for the parent form messages are disabled

<form id="ricarica_telefonica_form"
data-parsley-errors-messages-disabled>
<script>
   $(function(){
      $('#ricarica_telefonica_form').parsley();
   });
</script>

Additionally i am using a custom message visualization to show errors trought bootstrap tooltip

window.Parsley.on('field:error', function() { some code });

but my code is not being executed (it works when a field is invalidated trought parsley). What am I doing wrong? Is the method .addError managed correctly by parsley?


Solution

  • I found the solution, the right way is

    var instance = $('#field').parsley();
    instance.trigger('field-error',instance,{message:errorMessage});
    

    In this way the event is catch by the function that manage tooltip, where i use message attribute. The form is still valid for parsley, but at least i reached my scope.