2012-08-03 37 views
0

我有我已经用在CKEditor的一个文本区域:还包括后验证我的CKEditor文本区域与jQuery

<form name="product_edit" action="products.php" method="post" id="edit_form" enctype="multipart/form-data"> 
<textarea name="products_description" wrap="soft" cols="75%" rows="20" id="products_description"></textarea> 

的jQuery我有以下验证形式:

$(document).ready(function() { 
    $('#edit_form').submit(function() { 
    if ($('#products_description').val() == '') { 
     alert('Please include a product description.'); 
     return false; 
    } 
    }); // end submit() 
}); // end ready() 

我也有几个其他领域,我验证哪些不包括在内的简洁。

我的问题是,虽然所有其他领域的工作正常,文本区域有时不会。如果我输入东西,有时不会识别它,但仍会弹出警报。然后,如果我回去点击(我甚至不必输入任何内容),并尝试提交它的作品。

任何猜测为什么?

+0

你能发表所有的代码吗? – undefined 2012-08-03 22:35:22

+0

似乎很好的工作http://jsfiddle.net/DoomHamster/Gteqc/ – 2012-08-03 22:51:30

+0

@BradleyMountford是小提琴似乎工作,但它使用ckeditor? – 2012-08-04 10:09:29

回答

0

这仍然是一个问题?如果不是,发布您的解决方案。

CKEeditor不能像那样工作,你不会得到像$('#products_description').val()这样的数据。 CKEditor不直接使用textarea,它会生成一个iframe来代替它。要获得该值,请致电CKEDITOR.instances.editor1.getData(),其中editor1在您的案例中可能为products_description

0

这适用于我,虽然没有描述添加工作正常,但如果你把一些空间它被认为是content.Please添加必要的属性为您的textarea。 请包括jquery验证器和jQuery库。

$(document).ready(function() { 
    $('#edit_form').validate({ 
     ignore: [],   
     rules: { 
        products_description: { 
          required: function() 
          { 
            CKEDITOR.instances.products_description.updateElement(); 
          } 
         } 
        }, 
        messages: {    
        products_description: "مطلوب" 
        }, 
        /* use below section if required to place the error*/ 
        errorPlacement: function(error, element) 
        { 
         if (element.attr("name") == "products_description") 
         { 
         error.insertAfter("#cke_description"); 
         } else { 
         error.insertAfter(element); 
         } 
        } 
       }); 
    });