2016-11-22 81 views
1

即使在CKEditor中輸入文本後,JQuery驗證錯誤消息也不會消失。CKEditor和JQuery驗證:錯誤消息在輸入文本後不會消失

提琴手:http://jsfiddle.net/BmZ93/458/

代碼:

$(document).ready(function() { 
    $('#add-job').validate({ 
    ignore: [],   
    rules: { 
       editor1: { 
        required: function() 
        { 
         CKEDITOR.instances.editor1.updateElement(); 
        } 
        } 
       }, 
       messages: { 
       Job_Title: "Required", 
       Job_Location: "Required", 
       jobid: "Required", 
       Job_Cat: "Required", 
       editor1: "Required" 
       }, 
       /* use below section if required to place the error*/ 
       errorPlacement: function(error, element) 
       { 
        if (element.attr("name") == "editor1") 
        { 
         error.insertBefore("textarea#editor1"); 
        } else { 
         error.insertBefore(element); 
        } 
       } 
      }); 
}); 

enter image description here

後市展望: 一旦用戶輸入的CKEditor的一些文字,驗證錯誤消息應該消失。

任何建議/方向將不勝感激。

+0

哪些錯誤你指的是? –

+1

他意味着當用戶提交一個空表單時,它將顯示所需的錯誤,並且當用戶在CKEditor上輸入某些內容時,錯誤必須消失。 – Troyer

+0

添加快照。請驗證。 –

回答

2

您可以在JS添加此,它會隱藏錯誤時,CKEditor的內容有:

CKEDITOR.instances.editor1.on('change', function() {  
    if(CKEDITOR.instances.editor1.getData().length > 0) { 
     $('label[for="editor1"]').hide(); 
    } 
}); 

演示:http://jsfiddle.net/BmZ93/460/

+0

爲什麼不使用這個答案? –

+0

讓我在我的最後嘗試這個, –

+0

希望它對你有所幫助;) – Troyer

相關問題