Parsley.js - 访问 UI 已弃用。直接在实例上调用 'getErrorsMessages'

Parsley.js - Accessing UI is deprecated. Call 'getErrorsMessages' on the instance directly

我将 Parsley.js 更新到最新 2.7.2 后,它会在控制台上显示此消息

Accessing UI is deprecated. Call 'getErrorsMessages' on the instance directly

这是我的代码和工作版本:

$(".test-form").parsley({
    errorsContainer: function (ParsleyField) {
    return ParsleyField.$element.attr("title");
},
    errorsWrapper: false
});
window.Parsley.on('field:error', function (fieldInstance) {
    var messages = ParsleyUI.getErrorsMessages(fieldInstance);
  var errorMsg = messages.join(';');
  fieldInstance.$element.tooltip('dispose');
  fieldInstance.$element.tooltip({
      animation: true,
      container: 'body',
      placement: 'top',
      title: errorMsg
  });
});
window.Parsley.on('field:success', function (fieldInstance) {
    fieldInstance.$element.tooltip('dispose');
});

代码笔:https://codepen.io/weilinzung/pen/MvZPKb

我该如何解决?谢谢!

改变这个:

var messages = ParsleyUI.getErrorsMessages(fieldInstance);

对此:

var messages = fieldInstance.getErrorsMessages();

查找参考修复它:

$(".test-form").parsley({
    errorsContainer: function (ParsleyField) {
    return ParsleyField.$element.attr("title");
},
    errorsWrapper: false
});

window.Parsley.on('field:error', function (fieldInstance) {
  // var messages = ParsleyUI.getErrorsMessages(fieldInstance);
  // var errorMsg = messages.join(';');
  fieldInstance.$element.tooltip('dispose');
  fieldInstance.$element.tooltip({
    animation: true,
    container: 'body',
    placement: 'top',
    title: function () {
      return fieldInstance.getErrorsMessages().join(';');
    }
  });
});

window.Parsley.on('field:success', function (fieldInstance) {
    fieldInstance.$element.tooltip('dispose');
});

参考:Display parsley errors in bootstrap tooltip

要调试 Parsley 以查看哪些字段有错误,我使用此事件处理程序:

window.Parsley.on('field:error', function (fieldInstance) {
                           console.log(fieldInstance);
                           console.log(fieldInstance.getErrorsMessages());
                  });