Jump to:

23377 Posts in 18296 Topics by 2868 members

General Questions

SilverStripe Forums » General Questions » Page Comments - Javascript error

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1559 Views
  • Junglefish
    Avatar
    Community Member
    104 Posts

    Page Comments - Javascript error Link to this post

    Having enabled Page Comments on a page I have noticed a JS error.

    It occurs when you click anywhere on the page after having entered some text in the 'Comments' textarea.

    In IE the script halts the page from submitting (very bad). In FireFox the page submits, but the error is still there, and in Firebug I can get some details about it.

    The error says, "$("PageCommentInterface_Form_PostCommentForm").validate is not a function".

    I have been able to track this in the SS code as far as line 216 of /sapphire/forms/Validator.php where we see this block of code:

       '#$formID textarea' : {
          initialise: function() {
             if(!this.old_onblur) this.old_onblur = function() { return true; }
             if(!this.old_onfocus) this.old_onfocus = function() { return true; }
          },
          onblur : function() {
             if(this.old_onblur()) {
                return $('$formID').validate(this);
             }
          }
       },

    ...and it's the onblur call that causes the error.

    Can someone advise what I can do here? (I'm running SS 2.4.0)

    jf/

  • Willr
    Avatar
    Forum Moderator
    5490 Posts

    Re: Page Comments - Javascript error Link to this post

    Have you got any other javascript on this page? I ran into this issue and it was jquery_improvements calling noConflict() before jquery had loaded.

  • Junglefish
    Avatar
    Community Member
    104 Posts

    Re: Page Comments - Javascript error Link to this post

    Hi Willr

    Yes, there's plenty of other JS going on, but it's (mostly) from the standard implementation.

    I've attached the rendered source of the html page in question. Do you think you could take a look and see if you can spot where the conflict might be?

    jf/

    Attached Files
  • Willr
    Avatar
    Forum Moderator
    5490 Posts

    Re: Page Comments - Javascript error Link to this post

    Can't really debug from that but another way you can try to fix it is to block javascript files one at a time till you no longer get the error then work out why that files causing the trouble.

  • Junglefish
    Avatar
    Community Member
    104 Posts

    Re: Page Comments - Javascript error Link to this post

    Hi Willr

    Okay, I think it's something to do with these core files:
          /cms/code/sitefeatures/PageCommentInterface.php
          /sapphire/forms/Validator.php

    Here's how far I've traced it:
    In my rendered source code I eliminated one-by-one the JS files until the error stopped. That led me to this file:
          /thirdparty/behaviour/behaviour.js

    That file is included by:
          /cms/code/sitefeatures/PageCommentInterface.php
    So I commented it out.

    Something odd then happened. When I re-examined the source code being rendered I noticed that /thirdparty/behaviour/behaviour.js was still being included - but in a different place(!). I tracked it down to this file:
          /sapphire/forms/Validator.php

    So I'm not quite sure how that happens, but SS appears to be saying something like, "if behaviour.js is not already included by PageCommentInterface.php, then Validator.php will include it." I checked other permutations and I'll summarise below:

    Comment out from neither             - file is included by PageCommentInterface.php
    Comment out from PageCommentInterface.php only       - file is included by Validator.php
    Comment out from Validator.php only          - file is included by PageCommentInterface.php
    Comment out from both                - file is not included

    So, that's the first conumdrum.

    The second is that, as soon as I manage to stop the file from being included, I instantly hit a new error on page load:
          "Behaviour is not defined"
    which I imagine will be no surprise.

    So, where now? Am I even looking in the right place?

    jf/

  • Junglefish
    Avatar
    Community Member
    104 Posts

    Re: Page Comments - Javascript error Link to this post

    ^^bump^^

  • Junglefish
    Avatar
    Community Member
    104 Posts

    Re: Page Comments - Javascript error Link to this post

    Do I need to report this as a bug?

    jf/

  • Junglefish
    Avatar
    Community Member
    104 Posts

    Re: Page Comments - Javascript error Link to this post

    ^^bump^^

    1559 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.