Jquery 如何验证joomla 2.5默认文本编辑器?
如何使用jQuery验证模糊上的joomla默认文本编辑器 这是我用来获取文本编辑器的代码。例如,在/models/forms/newsitem.xml中:Jquery 如何验证joomla 2.5默认文本编辑器?,jquery,joomla,validation,joomla2.5,Jquery,Joomla,Validation,Joomla2.5,如何使用jQuery验证模糊上的joomla默认文本编辑器 这是我用来获取文本编辑器的代码。例如,在/models/forms/newsitem.xml中: <field name="description" type="editor" buttons="true" hide="pagebreak,readmore,article,image" class="inputbox required"
<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>
Joomla.submitbutton=函数(任务){
if(task==“newsitem.cancel”| | document.formvalidator.isValid(document.id('newsitem-form')){
submitform(任务、文档、getElementById('newItem-form');
}否则{
警报(“”);
}
}
我想要的是,我想在文本编辑器旁边显示一条警告消息,说“您不能将此留空”。我可以在表单提交中完成,但真正的挑战是如何在blur上完成。此代码
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的有效选择器。这仅在有一个编辑器时有效
希望这会有帮助。我知道了。更改了答案(登录-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>
Joomla.submitbutton=函数(任务){
if(task==“newsitem.cancel”| | document.formvalidator.isValid(document.id('newsitem-form')){
如果(任务!=“newsitem.cancel”){
var boolSubmit=true;
if(jQuery('#jform_description_parent')。是(':visible')){
jQuery(jQuery('#jform_description_parent iframe')[0]。contentWindow)。每个(函数(){
var editor_text=jQuery('#jform_description_parent iframe').contents().find('body').text();
如果(编辑器文本=“”){
警报(“”);
boolSubmit=false
}
});
}否则{
jQuery('textarea#jform_description')。每个(函数(){
if(jQuery(this).val()=''){
警报(“”);
boolSubmit=false;
}
});
}
如果(!boolSubmit)
返回布尔submit;
}
submitform(任务、文档、getElementById('newItem-form');
}否则{
警报(“”);
}
}
好的,结论?我想可以。嗨,伊凡。这是不可能的。没有错误输出。例如,我写了-$('jform_description')。blur。。。但在XML的类(管理中的编辑器)中不显示为“必需”。请帮忙。我需要。我在等你的答复,我忘了说。它是安装的JCE@Areku_UA:我已经更新了我的答案,也许这会指引你。事实证明,我是来改变你的答案的。看看我的答案。提前谢谢!