Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

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 Comments - Javascript error


Reply


8 Posts   1760 Views

Avatar
Junglefish

Community Member, 109 Posts

21 October 2010 at 10:01pm

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/

Avatar
Willr

Forum Moderator, 5513 Posts

23 October 2010 at 12:14am

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.

Avatar
Junglefish

Community Member, 109 Posts

23 October 2010 at 12:30am

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
Avatar
Willr

Forum Moderator, 5513 Posts

23 October 2010 at 10:40am

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.

Avatar
Junglefish

Community Member, 109 Posts

25 October 2010 at 10:51pm

Edited: 25/10/2010 10:54pm

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/

Avatar
Junglefish

Community Member, 109 Posts

28 October 2010 at 3:13am

^^bump^^

Avatar
Junglefish

Community Member, 109 Posts

3 November 2010 at 11:30pm

Do I need to report this as a bug?

jf/

Avatar
Junglefish

Community Member, 109 Posts

18 November 2010 at 10:29pm

^^bump^^