[英]Update textarea with CKEditor + jQuery Validation
我正在嘗試驗證包含CKEditor支持的textarea的表單。 但是現在,它根本不顯示任何錯誤,也沒有提交代碼。
我已經閱讀了與該主題相關的所有答案,但我的代碼無法正常工作。
到目前為止,這是我得到的:
if(jQuery().validate) {
$("#submit_button").click(function(e){
e.preventDefault();
CKEDITOR.instances.editor1.updateElement();
$(" #content_form ").validate({
ignore: "input:hidden:not(input:hidden.required),input:hidden:not(input:hidden.editor1)",
errorPlacement: function(error, element) {
if (element.attr("name") == "editor1")
{
error.insertBefore("#editor1");
}
else
{
error.insertAfter(element);
}
},
rules: {
title: {
required: true,
minlength: 5
},
editor1: {
required: true,
minlength: 10
},
imglink: {
url:true
},
},
messages: {
title: "The title field is required.",
editor1: "The content field is required.",
imglink: "You must provide a valid URL."
}
});
});
}
如果您能幫助解決這個問題,我將不勝感激。
提前致謝。
我正在做的事情是這樣的:
CKEDITOR.instances['txtSomeTextbox'].updateElement(); // this will update text in the hidden textbox that CKE is using.
// or if you have multiple instances
// for (var i in CKEDITOR.instances) {
//CKEDITOR.instances[i].updateElement(); // to update the textarea
//}
然后,我得到文本框的值,如下所示:
var mytext = CKEDITOR.instances.txtSomeTextbox.getData();
您現在可以使用mytext進行任何驗證。
您的問題之一是對.validate()
方法的基本誤解。
您的代碼...
$("#submit_button").click(function(e){
....
$(" #content_form ").validate({
....
由於.validate()
是插件的初始化方法,因此通常在DOM ready事件中調用一次 。 它不屬於提交按鈕的click
處理程序事件的內部,因為插件需要在單擊事件之前進行初始化。 ( 它不會被多次調用,因為所有后續調用都會被忽略。 )此外,該插件捕獲各種click事件並根據需要自動執行任何已定義的驗證。
$(document).ready(function() { // <-- DOM Ready event
....
$("#content_form").validate({ // <-- Initialize the plugin on this form
....
插件的基本演示: http : //jsfiddle.net/EN3Yb/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.