My solution for this (which is related to setting up WordPress TinyMCE):
jQuery( function ( $ ) { $( '.smyles-add-required-attr' ).attr( 'required', 'required' ); tinymce.on( 'AddEditor', function ( e ) { console.log( 'Added editor with id: ' + e.editor.id, e.editor ); var $editor = tinymce.get( e.editor.id ); $editor.on( "change", function (e){ $editor.save(); }); }); } );
The jQuery above adds the required flag (this can be done in many other ways) and ensures that the text area is updated after the change
To deal with the problem of a non-"focusable" element, just set the opacity and height so you can remove display: none;
This CSS assumes that you added the smyles-add-required-attr class to the editor when outputting using editor_class (for WordPress wp_editor )
textarea[style*="display: none"].smyles-add-required-attr:invalid { height: 0px !important; opacity: 0 !important; position: absolute !important; display: flex !important; margin-top: -75px; }
This adds a red border around the editor, suggesting that it is inside the fieldset in your form
.my-form fieldset:invalid .wp-editor-wrap { border: 1px solid red; }
One potential problem is that when the page loads, a red border is displayed around the fieldset , you can use fieldset:invalid:focus-within but be careful, it has limited browser support https://caniuse.com/#feat=css-focus -within
source share