Search code examples
phpjoomlajquery-validate

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: {            
            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>

Solution

  • 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.