简体   繁体   中英

CKEDITOR jQuery Validation in Firefox

I have 2 CKEditor fields that are being validated for input by jquery. Everything works perfect except in Firefox. For some reason, it doesn't check for those fields unless the CKEDITOR fields received input first. So, basically, if you enter the page and click on submit form button, it won't check for those fields, but if you put cursor inside the fields and try to validate then, it works. again, that only happens in Firefox.

The validation code is very simple:

var edt1 = CKEDITOR.instances['div1'].getData();

if (!edt1) {
    AppendErrorMessage("message.");
    ShowValidationIcon($('#icon'));
}
return true;

Any workaround to this problem?

I found a solution to this problem myself.

It was due to the fact that Firefox was automatically placing a bit of HTML, so the field wasn't actually empty. Here's the code that solved the problem for all browsers.

if (edt1 == "" || edt1 === "<br />\n") { do stuff }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM