ckeditor | the "required" attribute within <textarea> tag is not working

10,126

Please see: https://docs.ckeditor.com/ckeditor4/latest/api/CKEDITOR_editor.html#event-required

You need to assign an event handler to CKEditor which "replaces" native textarea element.


If you are looking for more fancy way of showing messages than standard alert dialogs, please try using notifications. Below is the most basic example (when you press submit button while having empty editor, notification will be displayed):

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

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

Please note that contrary to what is written in documentation the notification plugin seems to be included into every preset. You can check it by using search box of Available Plugins, list box in online builder.

Share:
10,126
CairoCoder
Author by

CairoCoder

I majored in Bioinformatics but have a passion for User Experience and Web Development. Everything I know about UI, UE, CSS, HTML, jQuery, PHP and MySQL was all self taught by looking online and buying books and video tutorials related to UX and Web Development. I have been continuously employed since high school and throughout college, which helped ramp me to my current positions at RAViN Jeanswear. I'm also in love with my current position at RAViN Jeanswear as Senior Web Developer and Team Leader. I am discovering that I seriously enjoy user flow, User Experience and Web Development, and would like to transition my career towards this wire-framing and development path. I love figuring out what makes users tick and click, also I adore developing easy to use and smooth back-ends. I also am getting serious about my Web Design, so feel free to message me if you would like a web design, psd to html/css or anything else! I would currently like to learn (or get to know better): User Experience Research, SASS, HTML 5, jQuery/jQuery-UI, JavaScript, AJAX, IOS Development. ------- Interesting Points of Discussion ------- 1. What's more important? Creating a product to create fantastic metrics? Or creating a product that creates a "good feeling" and a lasting impression? 2. When should you use tables, and when should you use CSS? Always CSS for presentation, of course! But sometimes divititis will get you down. How do you get around that? 3. Find me a way to wrap a really long word (like supercalifragilisticexpialidocious) onto the next line of a 20px width div in CSS that works in all browsers. (?) 4. When to use CMS, and when to start a "From Scratch" website? Specialties: HTML Markup, CSS, User Experience, User Interface, Photoshop, Photography, Agile, JIRA, PHP, OOP, JavaScript, jQuery, PHP Frameworks.

Updated on June 17, 2022

Comments

  • CairoCoder
    CairoCoder almost 2 years

    When using CKEDITOR with <textarea> tag, it's not working.

     <textarea id="editor1" name="description" class="form-control" cols="10" rows="10" required></textarea>
    
     <script>
          CKEDITOR.replace('editor1');
     </script>
    

    Any sugesstions?

  • CairoCoder
    CairoCoder about 6 years
    Can i get the native HTML validation (tooltip one), as this would be confusing (tooltip and alert within same form).
  • j.swiderski
    j.swiderski about 6 years
    I don't think you will show two messages because when CKEditor replaces the textarea it in fact set it to display:none so no tooltip validation will be fired here. If however you don't want to use alerts, you can try using notifications. Let me update my answer.