TinyMCE bugfix...

  • luciorota

    luciorota - 2008-12-11

    I'm fixing a TinyMCE bug...

    The standard javascript way to validate a textarea content:

    if (textarea.value == "")
    alert("textarea is empty");

    not work with TinyMCE editor so I have to override/replace the original
    renderValidationJS() method, defined in XoopsFormElement, with a costumized method in XoopsFormTinyMce Class

    How can I?

    • luciorota

      luciorota - 2008-12-16

      I'm debuging, debuging, debuging... ;-)

      Probabily there is a bug in Xoops 2.3.X... I'm looking for it
      Thanks for your time!


    • Julian Egelstaff


      To customize the validation JS, you need to assign the "customValidationCode" property of the form element Object that you want to have this validation code.

      This would presumably need to be done in the PHP code that constructs the element objects.


      $element = new xoopsFormRadio('Radio Button Caption', 'radioButtonsName');
      $element->addOption('apple', 'I like Apples');
      $element->addOption('oranges', 'I Like Oranges');
      // this custom validation code will give an error if the no radio option is selected
      $element->customValidationCode[] = "selection = false;\n";
      $element->customValidationCode[] = "for(i=0;i<myform.{$eltname}.options.length;i++) {\n";
      $element->customValidationCode[] = " if(myform.{$eltname}.options[i].selected) {\n";
      $element->customValidationCode[] = " selection = true;\n";
      $element->customValidationCode[] = " }\n";
      $element->customValidationCode[] = "}\n";
      $element->customValidationCode[] = "if(selection == false) { window.alert(\&quot;{$eltmsg}\&quot;);\n myform.{$eltname}.focus();\n return false;\n }\n";

      So customValidationCode is an array, and basically, each array element is one line of javascript code that will be executed when the form is validated. $eltname is the name of the form element, and $eltmsg is a special message XOOPS constructs to tell people they need to fill in the element.

      This only works in conjunction with the form class of course, I'm not sure how applicable it may be to your TinyMCE situation.

      Does this make sense?


    • luciorota

      luciorota - 2008-12-16


      But I should override/replace the original renderValidationJS() method, defined in XoopsFormElement, with a costumized method in XoopsFormTinyMce Class, everytime I use this class...

      I've just added this Method to the XoopsFormTinyMce Class (look Xoops SVN) but Xoops doesn't use the just created method...


      • Julian Egelstaff

        Hmmm, this is a debugging task, and it's pretty impossible to remotely debug code via forum. :-) I assume you're using 2.3? I don't have a reference copy of that codebase handy to check the form classes right now either. But if it's like 2.0.18, then the form should call the renderValidationJS method on every element.

        So the questions are....

        • is your method called renderValidationJS? Or whatever the 2.3 code expects that method to be called (check xoopsform/form.php to see).

        • does that method return a string of javascript code? If not, that might be the problem. Does the method have some bug or error in it that would result in nothing being returned

        • does the form include any validation code for any elements? Maybe the whole rendering of validation code is not working for some reason.

        Debug, debug, debug.

        The trick is figuring out for sure if your method is being called as you expect, when you expect. Simplifying the method so it returns something obvious that is easy to check the HTML source code for, that's a good way to start. If it is outputting something, then the trick is figuring out why it's not outputting what you think it should when the full code you wrote is being used.

        Paste in your renderValidationJS method from the tinymce class, maybe there's a hint in there.


  • Anonymous - 2016-03-03
    Last edit: Anonymous 2016-04-01

Log in to post a comment.