How to make Ckeditor mandatory to fill in as a required attribute

Asked

Viewed 213 times

0

I cannot make the ckeditor behave like an input field or textarea with required

<textarea data-toggle="tooltip" maxlenfth="200" data-maxlen="200" class="form-control" rows="2" id="cumprimentos" name="cumprimentos" required>
</textarea>
<script type="text/javascript">
  CKEDITOR.replace('cumprimentos', {
    toolbar: [],
    height: 110,
    contentsCss: 'body {overflow:hidden;  font-family: sans-serif, Arial, Verdana, "Trebuchet MS", "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";font-size: 13px;color:#333;}',
    enterMode: Number(2),
    extraPlugins: 'forms',
    extraPlugins: 'html5validation',
    extraPlugins: 'wordcount',

    wordcount: {
      showWordCount: false,
      showParagraphs: false,
      showCharCount: true,
      maxCharCount: 200,
    }

  });
</script>

2 answers

1

First you have to assign the plugin to a variable:

var editor = CKEDITOR.replace('cumprimentos', {...

Note that now the Ckeditor instance has a name, editor.

Then you use the event required editor. If the field is empty, the alert and cancel sending the form:

editor.on('required', function(e){
    alert("preencha o campo");
    e.cancel();
});
  • But, Sam, even so the form is submited and gives error. Despite having given the Alert.

  • Actually form Ubmit input gets disable after Alert.

1

Browser other questions tagged

You are not signed in. Login or sign up in order to post.