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.

Customising the CMS

Random JavaScript at the bottom of the page code


Reply

3 Posts   1755 Views

Avatar
Alex S

7 September 2009 at 4:07am (Last edited: 7 September 2009 4:09am), Community Member, 30 Posts

Hey,

This is a follow-on I guess from this thread: http://www.silverstripe.org/archive/show/1406#post1406 . Basically, there's a lump of JavaScript appearing towards the end of my page code which is preventing anything like light-whatever or JQuery from functioning. It's as follows:

<script type="text/javascript" src="http://mysite/jsparty/prototype.js?m=1226464322"></script><script type="text/javascript" src="http://mysite/jsparty/behaviour.js?m=1228253400"></script><script type="text/javascript" src="http://mysite/jsparty/prototype_improvements.js?m=1195165918"></script><script type="text/javascript" src="http://mysite/sapphire/javascript/i18n.js?m=1236311236"></script><script type="text/javascript" src="http://mysite/sapphire/javascript/lang/en_US.js?m=1229303948"></script><script type="text/javascript" src="http://mysite/sapphire/javascript/Validator.js?m=1236311236"></script><script type="text/javascript">//<![CDATA[
Behaviour.register({
   '#SearchForm_SearchForm': {
      validate : function(fromAnOnBlur) {
         initialiseForm(this, fromAnOnBlur);
         
         
         var error = hasHadFormError();
         if(!error && fromAnOnBlur) clearErrorMessage(fromAnOnBlur);
         
         return !error;
      },
      onsubmit : function() {
         if(typeof this.bypassValidation == 'undefined' || !this.bypassValidation) return this.validate();
      }
   },
   '#SearchForm_SearchForm input' : {
      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()) {
            // Don't perform instant validation for CalendarDateField fields; it creates usability wierdness.
            if(this.parentNode.className.indexOf('calendardate') == -1 || this.value) {
               return $('SearchForm_SearchForm').validate(this);
            } else {
               return true;
            }
         }
      }
   },
   '#SearchForm_SearchForm select' : {
      initialise: function() {
         if(!this.old_onblur) this.old_onblur = function() { return true; }
      },
      onblur : function() {
         if(this.old_onblur()) {
            return $('SearchForm_SearchForm').validate(this);
         }
      }
   }
});

//]]></script>

I figure it's probably quite necessary for some pages, like pages with comments on, but it appears for any and every page, regardless of whether the comments system is switched on or not. It even pops up when the "$PageComments" is removed from the template. Is there any way to make this a little more targeted, so it only gets included where it's needed?

Any ideas would be greatly appreciated.

Cheers,

Alex

Avatar
Willr

7 September 2009 at 11:45am Forum Moderator, 5511 Posts

Behaviour.register({
'#SearchForm_SearchForm': {
validate : function(fromAnOnBlur) {

Looks like its the validation JS for the built in search form if you are using that?. You should be able to run jquery fine with it as long as you run it as listed on http://doc.silverstripe.com/doku.php?id=jquery#examples.

You can completely disable it by adding this to your _config file - Validator::set_javascript_validation_handler('none');

Avatar
Alex S

8 September 2009 at 3:56am Community Member, 30 Posts

Hey,

Thanks for looking, I tried your suggestion of adding "Validator::set_javascript_validation_handler('none');" to my _config file and that's removed everything that was causing an issue. I'll have a read through the docs about the search validation and see what side effects this will have.

With the JQuery, I was implementing a modal window as described here: http://www.queness.com/post/77/simple-jquery-modal-window-tutorial which still seemed to require the link to prototype.js to be removed from that bottom set of links for it to work. It also required the "<base..." tag to be removed from the header too though so I figured that a light window solution would be best in the end.

Cheers for the advice,

Alex