【问题标题】:How to validate joomla 2.5 default text editor?如何验证 joomla 2.5 默认文本编辑器?
【发布时间】:2013-02-15 13:52:44
【问题描述】:

如何使用 jQuery 在模糊上验证 joomla 默认文本编辑器?

这是我用来获取文本编辑器的代码。示例,在 /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>

我想要的是我想在文本编辑器旁边显示一条警告消息,说“你不能把这个留空”。我可以在表单提交中做到这一点,但真正的挑战是如何在模糊中做到这一点。

【问题讨论】:

    标签: jquery joomla validation joomla2.5


    【解决方案1】:

    如果表单中只有编辑器,则此代码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 的有效选择器,这仅在有一个编辑器时才有效

    希望这会有所帮助。

    【讨论】:

    • 嗨,伊尔凡。是不可能的。没有错误输出。例如,我写了 - $('#jform_description').blur... 但在 XML 的类(管理员中的编辑器)中没有出现“必需”。请帮忙。我需要。我等待你的回复
    • 我忘了说。它已安装 JCE
    • @Areku_UA:我已经更新了我的答案,这可能会指导你。
    • 嘿。我来改变你的答案,结果。看我的回答。提前致谢!
    【解决方案2】:

    我明白了。更改了答案(登录 - 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>
    

    好的结论?我认为这可能没问题。

    【讨论】:

      猜你喜欢
      • 2011-03-10
      • 1970-01-01
      • 2014-07-10
      • 2012-10-09
      • 2013-10-08
      • 1970-01-01
      • 2015-05-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多