2013-02-15 44 views
0

如何驗證使用jQuery模糊Joomla默認文本編輯器?如何驗證joomla 2.5默認文本編輯器?

這是我使用得到的文本編輯器的代碼。例如,在/models/forms/newsitem.xml:

<field name="description" type="editor" buttons="true" 
        hide="pagebreak,readmore,article,image" 
        class="inputbox required" 
        filter="JComponentHelper::filterText" 
        label="JGLOBAL_DESCRIPTION" 
        description="COM_NEWSITEMS_FIELD_DESCRIPTION_DESC" required="true" /> 

第二個文件(/views/.../edit.php) - 什麼樣的新對象添加到JavaScript的?

<script type="text/javascript"> 
    Joomla.submitbutton = function(task) { 
     if (task == 'newsitem.cancel' || document.formvalidator.isValid(document.id('newsitem-form'))) { 
      <?php echo $this->form->getField('description')->save(); ?> 
      Joomla.submitform(task, document.getElementById('newsitem-form')); 
     } else { 
      alert('<?php echo $this->escape(JText::_('JGLOBAL_VALIDATION_FORM_FAILED'));?>'); 
     } 
    } 
</script> 

我要的是我想告訴旁邊的文本編輯器警告消息,說:「你不能離開這個空白」。我可以在表單提交中做到這一點,但真正的挑戰是如何做到模糊。

回答

0

我懂了。更改答案(登錄 - Irfan),但它應該是 - 如果單擊「保存」,則編輯器顯示錯誤(空文本)。這裏有一個例子:

<script type="text/javascript">  
    Joomla.submitbutton = function(task) { 
     if (task == 'newsitem.cancel' || document.formvalidator.isValid(document.id('newsitem-form'))) { 
      if(task != 'newsitem.cancel') { 
      var boolSubmit = true; 
      if(jQuery('#jform_description_parent').is(':visible')) { 
       jQuery(jQuery('#jform_description_parent iframe')[0].contentWindow).each(function() { 
        var editor_text = jQuery('#jform_description_parent iframe').contents().find('body').text(); 
        if(editor_text=='') { 
         alert('<?php echo $this->escape(JText::_('JGLOBAL_VALIDATION_FORM_FAILED'));?>'); 
         boolSubmit = false 
        } 
       }); 
      } else { 
       jQuery('textarea#jform_description').each(function() { 
        if(jQuery(this).val()=='') { 
         alert('<?php echo $this->escape(JText::_('JGLOBAL_VALIDATION_FORM_FAILED'));?>'); 
         boolSubmit = false; 
        } 
       }); 
      } 
      if(!boolSubmit) 
       return boolSubmit; 
      } 
      <?php echo $this->form->getField('description')->save(); ?>    
      Joomla.submitform(task, document.getElementById('newsitem-form')); 
     } else { 
      alert('<?php echo $this->escape(JText::_('JGLOBAL_VALIDATION_FORM_FAILED'));?>'); 
     } 
    } 
</script> 

好的結論?我想這可能會好的。

0

此代碼document.formvalidator.isValid(document.id('newsitem-form'))驗證您的形式,如果只是編輯器中存在的形式,你可以試試這個 -

jQuery('#editorid').blur(function() { 
    if(!document.formvalidator.isValid(document.id('newsitem-form'))){ 
    //Add your error message code 

    } 
}); 

更新: -

jQuery(jQuery('iframe')[0].contentWindow).blur(function() { 
var editor_text = jQuery('iframe').contents().find('body').text(); 
if(editor_text=='')alert('Error message'); 
}); 

注: - 使用有效的選擇器指向編輯器的iframe,這將只適用於有一個編輯器

希望這會有所幫助。

+0

嗨,Irfan。是不可能的。沒有錯誤輸出。例如,我寫了 - $('#jform_description')。blur ...但在XML的類(編輯器管理員)中沒有出現'required'。請幫助。我需要。我等待你的回覆 – 2013-02-18 12:24:50

+0

我忘了說。它被安裝JCE – 2013-02-18 12:44:24

+0

@Areku_UA:我已經更新了我的答案,可能會引導你。 – Irfan 2013-02-18 13:52:31

相關問題