Block the form submit if one or more editors are still in source code mode
authorAlexander Ebert <ebert@woltlab.com>
Fri, 9 Apr 2021 15:34:56 +0000 (17:34 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 9 Apr 2021 15:34:56 +0000 (17:34 +0200)
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabSource.js

index eb52b63a2b17dc68b4696812c5b34c2bb335f5cd..eab7d7ba3dc1383206f09fa005c3d7c79f54f7da 100644 (file)
@@ -114,6 +114,40 @@ $.Redactor.prototype.WoltLabSource = function() {
                                        data.valid = false;
                                }
                        }).bind(this));
+
+                       var box = this.core.box()[0];
+                       var form = box.closest("form");
+                       if (form) {
+                               var dl = box.closest("dl");
+
+                               form.addEventListener("submit", (function (event) {
+                                       var message = '';
+                                       if (this.WoltLabSource.isActive()) {
+                                               event.preventDefault();
+
+                                               message = WCF.Language.get('wcf.editor.source.error.active');
+
+                                               // Enable the submit button again to override the FormGuard's behavior.
+                                               var submitButton = form.querySelector(".formSubmit input[type=submit]");
+                                               if (submitButton) {
+                                                       submitButton.disabled = false;
+                                               }
+
+                                               require(['WoltLabSuite/Core/Ui/TabMenu'], function(UiTabMenu) {
+                                                       UiTabMenu._selectErroneousTabs();
+                                               });
+                                       }
+
+                                       elInnerError(box, message);
+
+                                       if (message) {
+                                               dl.classList.add("formError");
+                                       }
+                                       else {
+                                               dl.classList.remove("formError");
+                                       }
+                               }).bind(this));
+                       }
                },
                
                isActive: function () {