diff --git a/wysiwyg.js b/wysiwyg.js index 38146e2..356cb95 100644 --- a/wysiwyg.js +++ b/wysiwyg.js @@ -347,6 +347,15 @@ function attachToField(context, params, editorSettings) { if (typeof Drupal.wysiwyg.editor.instance[editor] == 'object') { jQuery.extend(true, Drupal.wysiwyg.instances[params.field], Drupal.wysiwyg.editor.instance[editor]); } + // 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 (params.status && field.attr('required')) { + field.attr('data-editor-required', true); + field.removeAttr('required'); + } // Settings are deep merged (cloned) to prevent editor implementations from // permanently modifying them while attaching. if (typeof Drupal.wysiwyg.editor.attach[editor] == 'function') { @@ -433,6 +442,13 @@ function detachFromField(context, params, trigger) { if (jQuery.isFunction(Drupal.wysiwyg.editor.detach[editor])) { Drupal.wysiwyg.editor.detach[editor](context, params, trigger); } + // Restore the HTML5 validation "required" attribute if it was removed in + // attachToField(). + var field = $('#' + params.field); + if (field.attr('data-editor-required')) { + field.attr('required', 'required'); + field.removeAttr('data-editor-required'); + } if (trigger == 'unload') { delete Drupal.wysiwyg.instances[params.field]; }