2015-12-11 17 views
1

我從Parsley 2.0.6升級到2.2.0,現在我在控制檯中得到這個警告:Parsley's pubsub module is deprecated; use the 'on' and 'off' methods on parsley instances or window.Parsley。一切仍然有效,包括由parsley事件監聽器觸發的函數,其中(我相信)這個錯誤發現它的根。但我得到警告。每當我做東西來刪除警告,那麼該功能不會運行。歐芹升級拋出PubSub棄用錯誤

我已將$.listen('parsley:field:validated')更改爲jQuery .on()的每個組合。我也將香菜事件更新爲`field:validated'。無論我做什麼,我的功能都無法運行。這是原始相關代碼的一大塊。這是工作的代碼,但顯示在控制檯的警告:

// check forms for data-parsley-validate attribute. If exests, then extend the config 
// with the trigger:'change' option. 
$('form, .form').each(function() { 
    var $form = $(this); 
    if($form.is('[data-parsley-validate]')) { 
     ParsleyConfig = $.extend(ParsleyConfig || {}, { 
      trigger: 'change' 
     }); 
    } 
    $form.parsley(); 
}); 


$(function() { 
    // Validation listener for ajdusting height of certain other components/widgets 
    $.listen('parsley:form:validated', $('[data-modal]'), function() { 
     if (typeof modalHeightSetter == 'function') { modalHeightSetter(); } 
    }); 

    // Validation listener for add/removal of .error class from .field-icon's 
    $.listen('parsley:field:validated', $('[data-field-icon]'), function() { 
     var $fieldIcons = $(this); 
     $fieldIcons.each(function() { 
      var $this = $(this); 
      if($this.is('.error')) { 
       $this.prev('.field-icon').addClass('error'); 
      } else if(! $this.is('.error')) { 
       $this.prev('.field-icon').removeClass('error'); 
      } 
     }); 
    }); 
}); 

我重寫了每個問題的JS什麼,我覺得@馬克 - 安德烈說,但得到的deprication警告要離開的相同的結果,但功能沒有運行。

// check forms for data-parsley-validate attribute. If exests, then extend the config 
// with the trigger:'change' option. 
$('form, .form').each(function() { 
    var $form = $(this); 
    if($form.is('[data-parsley-validate]')) { 
     ParsleyConfig = $.extend(ParsleyConfig || {}, { 
      trigger: 'change' 
     }); 
    } 
    $form.parsley(); 
    // Validation listener for ajdusting height of certain other components/widgets 
    $form.parsley().on('form:validated', $('[data-modal]'), function() { 
     if (typeof modalHeightSetter == 'function') { modalHeightSetter(); } 
    }); 

    // Validation listener for add/removal of .error class from .field-icon's 
    $form.parsley().on('field:validated', $('[data-field-icon]'), function() { 
     var $fieldIcons = $(this); 
     $fieldIcons.each(function() { 
      var $this = $(this); 
      if($this.is('.error')) { 
       $this.prev('.field-icon').addClass('error'); 
      } else if(! $this.is('.error')) { 
       $this.prev('.field-icon').removeClass('error'); 
      } 
     }); 
    }); 
}); 

回答

0

檢查the doc ...的onoff方法不是jQuery的,但香菜的...

+0

如果我做'$( '形式')上( '形式:驗證')。... '功能永遠不會運行 – Ben

+0

哦,我想我明白你的意思了。測試它 – Ben

+0

沒有工作。查看編輯的問題。 – Ben