如何验证 joomla 默认文本编辑器?

发布于 2024-09-07 14:55:34 字数 1400 浏览 2 评论 0原文

我使用 joomla 默认编辑器作为表单和 jquery 验证器插件,现在我想验证 joomla 文本编辑器不应该为空......我该如何验证?

我读了一篇关于tinymce验证的文章,我想要类似于这篇文章

虽然如果我点击切换编辑器比验证有效(因为它变成了teaxarea),但是当有joomla默认编辑器时,当它为空时不会显示任何错误,

这是所需的代码

<script type="text/javascript">
jQuery(document).ready(function(){
    jQuery("#addBookForm").validate({
        rules: {            
            description: "required"             
        },
        messages: {         
            description:"Please write description",         
        }
    });
});
</script>
<form id="addBookForm"  action="" method="post" >       
    <table width="100%" border="0" cellpadding="4" cellspacing="2">
        <tr>
            <td>Description :</td>
            <td >
        <?php
            $editor =& JFactory::getEditor();
            $params = array('smilies'=> '0' ,'style'  => '0' ,'layer'  => '0' ,'table'  => '0' ,'clear_entities'=>'0');
            $value = isset($this->data['description']) ? $this->data['description'] : '';
            echo $editor->display('description', $value,'400','300','20','20',false, $params);
        ?>
            </td>
        </tr>       
    </table>    
</form>

i m using joomla default editor for a form and jquery validator plugin, now i want to validate that joomla text editor should not be blank.... how do i validate that??

i read an article regarding validation for tinymce, i want similar to this post

although if i click on toggle editor than validation works( coz it turn into teaxarea) but when there is joomla default editor then does not display any error when it is blank

here is the reuired code

<script type="text/javascript">
jQuery(document).ready(function(){
    jQuery("#addBookForm").validate({
        rules: {            
            description: "required"             
        },
        messages: {         
            description:"Please write description",         
        }
    });
});
</script>
<form id="addBookForm"  action="" method="post" >       
    <table width="100%" border="0" cellpadding="4" cellspacing="2">
        <tr>
            <td>Description :</td>
            <td >
        <?php
            $editor =& JFactory::getEditor();
            $params = array('smilies'=> '0' ,'style'  => '0' ,'layer'  => '0' ,'table'  => '0' ,'clear_entities'=>'0');
            $value = isset($this->data['description']) ? $this->data['description'] : '';
            echo $editor->display('description', $value,'400','300','20','20',false, $params);
        ?>
            </td>
        </tr>       
    </table>    
</form>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

开始看清了 2024-09-14 14:55:39

这是一个老问题,但仍然相关,并且仍然很难找到直接的答案。

您可以仅通过 JavaScript 轻松检查编辑器是否为空:

if (!Joomla.editors.instances['jform_myid'].getValue()) {
  // Editor is empty
  return false;
}

其中 myid = 编辑器字段 id

This is an old question but still relevant and still difficult to find a straightforward answer.

You can easily check whether the editor is empty via javascript only:

if (!Joomla.editors.instances['jform_myid'].getValue()) {
  // Editor is empty
  return false;
}

where myid = editor field id

梦言归人 2024-09-14 14:55:38

您可以通过为视图添加以下代码来实现此目的

$js="function validateEditor(){
        var content = ".$editor->getContent('editorName').";
        return content;                 
    }";
$document =& JFactory::getDocument();
$document->addScriptDeclaration($js);

,并在提交表单之前调用此 java 脚本函数 (validateEditor)。

You can achieve this by adding the following code for your view

$js="function validateEditor(){
        var content = ".$editor->getContent('editorName').";
        return content;                 
    }";
$document =& JFactory::getDocument();
$document->addScriptDeclaration($js);

And call this java script function (validateEditor) before submitting the form.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文