如何通过在其旁边添加字符串来验证tinyMCE编辑器是否为空白? [英] How do I validate a tinyMCE editor, if it is blank by appending a string next to it?

查看:422
本文介绍了如何通过在其旁边添加字符串来验证tinyMCE编辑器是否为空白?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要验证表单。这个表单有一些下拉列表和tinyMCE编辑器,我通过在每个字段后附加字符串Required来验证这个表单,如果它是空白的,但是我无法验证tinyMCE编辑器,如果编辑器是空白的,我尝试了类似

I need to validate a form. This form has some dropdowns and tinyMCE editor, I am validating this form by appending the string "Required" after each field if it is blank, However I am unable to validate the tinyMCE editor, if the editor is blank, I tried something like

tinyMCE.get('tinyedotor').getContent();

但没有运气。

这里是我的小提琴

推荐答案

getContent()应该可以正常工作。您的小提琴不包含编辑器值的表单验证代码,这在此非常重要。试试这个:

getContent() should work just fine. Your fiddle doesn't contain the form validation code for the editor value, which is quite crucial here. Try this:

var editorContent = tinyMCE.get('tinyeditor').getContent();
if (editorContent == '')
{
    // Editor empty
}
else
{
    // Editor contains a value
}

分叉小提琴

另请注意,您已声明多个 id 用于选择下拉菜单。

Also note you've declared multiple id's for your select drop-down.

编辑你可以获得带有 getContainer()方法的编辑器容器的 id tinyMCE.get('tinyeditor ).getContainer()。在编辑器之后插入错误消息将是这样的:

You can get the id of the editor container with the getContainer() method: tinyMCE.get('tinyeditor').getContainer(). Inserting an error message after the editor would then be something like this:

$('<span class="error">Editor empty</span>').insertAfter($(tinyMCE.get('tinyeditor').getContainer()));

然而,这将创建一个新的 span 每次用户单击提交按钮时,您可能希望拥有一个带有唯一 id 的错误消息容器,并在插入之前检查容器是否已存在。

This, however, will create a new span each time the user clicks the submit button, so you'll probably want to have an error message container with a unique id and check if the container already exists before inserting it.

编辑2 更新小提琴

这篇关于如何通过在其旁边添加字符串来验证tinyMCE编辑器是否为空白?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆