开发者

how to validate joomla default text editor?

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: {    开发者_JAVA百科        
            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>


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜