ckeditor | &#34;必需&#34; <textarea>标记内的属性不起作用

时间:2018-04-30 12:49:57

标签: validation ckeditor textarea required

&lt; p&gt;使用&lt; code&gt; CKEDITOR&lt; / code&gt;时与&lt; code&gt;&lt; textarea&gt;&lt; / code&gt;标签,它不起作用。&lt; / p&gt; &LT;预&GT;&LT;代码&GT; &lt; textarea id =&#34; editor1&#34;命名=&#34;描述&#34;类=&#34;形状控制&#34; COLS =&#34; 10&#34;行=&#34; 10&#34;所需&GT;&LT; / textarea的&GT;  &LT;脚本&GT;       CKEDITOR.replace(&#39; editor1&#39);  &LT; /脚本&GT; &LT; /代码&GT;&LT; /预&GT; &lt; p&gt;任何sugesstions?&lt; / p&gt;

2 个答案:

答案 0 :(得分:1)

请参阅:https://docs.ckeditor.com/ckeditor4/latest/api/CKEDITOR_editor.html#event-required

您需要为CKEditor分配一个事件处理程序,其中&#34;替换&#34;原生textarea元素。

如果您正在寻找比标准提醒对话框更有趣的显示消息的方式,请尝试使用notifications。以下是最基本的示例(当您在空编辑器中按submit按钮时,将显示通知):

var editor = CKEDITOR.replace( 'editor1', {
    language: 'en',
    extraPlugins: 'notification'
});

editor.on( 'required', function( evt ) {
    editor.showNotification( 'This field is required.', 'warning' );
    evt.cancel();
} );

请注意,与文档中的内容相反,notification插件似乎包含在每个预设中。您可以使用Available Plugins中的Hr usr Hi usr Jk usrtest user 搜索框,online builder中的列表框进行检查。

答案 1 :(得分:0)

您可以使用

<script>
function validate() {
    var resultado_validacion=true;
    $("#editor_error").html("");
    var editor_val = CKEDITOR.instances.editor.document.getBody().getChild(0).getText().trim();
    if(!(editor_val.length>0)){
        $("#editor_error").html("Se requiere contenido del oficio");
        resultado_validacion=false;
    }       

    return resultado_validacion;
}

</script>    
<form  onSubmit="return validate();">