When there is a contenteditable element in the form, clicking on that element to focus it causes javascript errors. This is reproducible in Firefox 44 and Chrome 49.
The error raised is "TypeError: owner is undefined" or similar.
I have a feeling this is due to delegate() in init(), as contenteditable elements do not have a this.form attribute.
Here is an example (sorry I am not smart enough to automate the focus click, that has to be done manually):
https://jsfiddle.net/w3zrrzyk/
I confirm. The delegate method should be changed to work with contenteditable elements.
This was breaking WYSIWYG functionality on a project (same console errors, plus all toolbar buttons took two clicks to trigger).
This was my quick hack of src/core.js to get it working:
function delegate( event ) {
//var validator = $.data( this.form, "validator" ),
var validator = $.data( $(this).parents('form')[0], "validator" ),
eventType = "on" + event.type.replace( /^validate/, "" ),
settings = validator.settings;
if ( settings[ eventType ] && !$( this ).is( settings.ignore ) ) {
settings[ eventType ].call( validator, this, event );
}
}
The fix doesn't sit right with me, but it seems to work for now (and I'm facing a tight deadline). Hopefully a more robust solution can be pushed through soon.
(In case it's relevant, we're using Trumbowyg as the editor)
Edit: Fix is not actually working, looks like I'll have to decide which feature to scrap for now.
Edit 2: I don't need validation on contentEditable elements, so I just rolled back to 1.14.0 (before this feature was added) and everything is good now.
Yup, this is an issue. It still occurs if you include your contenteditable in 'ignore'.
Could someone confirm that https://github.com/jzaefferer/jquery-validation/pull/1778 fixes this issue?
$.validator.defaults.onfocusout still has problem with contenteditable
Uncaught TypeError: Cannot read property 'replace' of undefined
js
// source http://stackoverflow.com/a/12254194
function injectTrim(handler) {
return function (element, event) {
if (element.tagName === "TEXTAREA" || (element.tagName === "INPUT"
&& element.type !== "password")) {
element.value = $.trim(element.value);
}
return handler.call(this, element, event);
};
}
$("form").validate({
onfocusout: injectTrim($.validator.defaults.onfocusout)
});
Most helpful comment
This was breaking WYSIWYG functionality on a project (same console errors, plus all toolbar buttons took two clicks to trigger).
This was my quick hack of src/core.js to get it working:
The fix doesn't sit right with me, but it seems to work for now (and I'm facing a tight deadline). Hopefully a more robust solution can be pushed through soon.
(In case it's relevant, we're using Trumbowyg as the editor)
Edit: Fix is not actually working, looks like I'll have to decide which feature to scrap for now.
Edit 2: I don't need validation on contentEditable elements, so I just rolled back to 1.14.0 (before this feature was added) and everything is good now.