diff --git a/wysiwyg.js b/wysiwyg.js index 29e2c54..275579e 100644 --- a/wysiwyg.js +++ b/wysiwyg.js @@ -134,6 +134,17 @@ Drupal.wysiwygAttach = function(context, params) { else { $('#wysiwyg-toggle-' + params.field).hide(); } + + // HTML5 validation cannot ever work for WYSIWYG editors, because WYSIWYG + // editors always hide the underlying textarea element, which prevents + // browsers from putting the error message bubble in the right location. + // Hence: disable HTML5 validation for this element. + var field = $('#' + params.field); + if (field.attr('required')) { + field.attr('data-editor-required', true); + field.removeAttr('required'); + } + // Attach editor, if enabled by default or last state was enabled. if (params.status) { Drupal.wysiwyg.editor.attach[params.editor](context, params, (Drupal.settings.wysiwyg.configs[params.editor] ? jQuery.extend(true, {}, Drupal.settings.wysiwyg.configs[params.editor][params.format]) : {})); @@ -166,6 +177,14 @@ Drupal.wysiwygDetach = function (context, params, trigger) { trigger = trigger || 'unload'; var editor = Drupal.wysiwyg.instances[params.field].editor; if (jQuery.isFunction(Drupal.wysiwyg.editor.detach[editor])) { + // Restore the HTML5 validation "required" attribute if it was removed in + // Drupal.editorAttach(). + var field = $('#' + params.field); + if (field.attr('data-editor-required')) { + field.attr('required', 'required'); + field.removeAttr('data-editor-required'); + } + Drupal.wysiwyg.editor.detach[editor](context, params, trigger); } };