sleemanj / xinha

WYSIWYG HTML Editor Component (turns <textarea> into HTML editors)
http://trac.xinha.org/
Other
13 stars 2 forks source link

onsubmit sometimes fails (Trac #100) #100

Closed sleemanj closed 4 years ago

sleemanj commented 20 years ago

While integrating Xinha into the Bricolage content management system, I came across an error when multiple Xinhas are on one page. The problem comes up in Xinha's onsubmit() method, which, when there are multiple Xinhas, is called multiple times. The subsequent calls fail because this.__msh_prevOnSubmit is undefined, so "a" has no properties, and calling "a.length" causes a fatal error.

Patch:

Index: htmlarea.js
===================================================================
--- htmlarea.js (revision 52)
+++ htmlarea.js (working copy)
@@ -1053,16 +1053,19 @@
       editor._textArea.value = editor.outwardHtml(editor.getHTML());
       var a = this.__msh_prevOnSubmit;
       // call previous submit methods if they were there.
-      var allOK = true;
-      for (var i = a.length; --i >= 0;)
+      if (typeof a != "undefined")
       {
-        if(a[i]() == false)
+        var allOK = true;
+        for (var i = a.length; --i >= 0;)
         {
-          allOK = false;
-          break;
+            if(a[i]() == false)
+            {
+            allOK = false;
+            break;
+            }
         }
+        return allOK;
       }
-      return allOK;
     };
     if (typeof f.onreset == "function") {
       var funcref = f.onreset;

Reported by marshall@exclupen.com, migrated from http://trac.xinha.org/ticket/100

sleemanj commented 20 years ago

I've fixed this problem in changeset:55 this patch was not quite correct I think, but thanks for alerting me to the problem.