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

jQuery conflict with userforms


Reply


4 Posts   2309 Views

Avatar
s_a_m_y

Community Member, 26 Posts

9 March 2011 at 12:15am

Some threads indicate there is a general chance of jQuery-conflicts with userforms.

I am using jQuery jScrollPane for individual ScrollPanes on a project. Works perfectly on all extended Pages except the ones where I use UDF. On these nothing happens and I get thrown the Error:

      Uncaught TypeError: Object #<an Object> has no method 'jScrollPane'

Others seem to also have troubles adding their own jQuery-Code to UDF-pages. I haven't found a proper solution though. I have included the script files in the Page.php:

      Requirements::javascript("mysite/javascript/jquery-1.4.2.js");
      Requirements::javascript("mysite/javascript/jquery-ui-1.8.custom.min.js");
      Requirements::javascript("mysite/javascript/jquery.mousewheel.js");
      Requirements::javascript("mysite/javascript/jquery.jscrollpane.js");
      Requirements::javascript("mysite/javascript/mwheelIntent.js");
      Requirements::javascript("mysite/javascript/bgss_script.js");

They all get loaded correctly, and, as said, work perfectly on all other pages. I appreciate any suggestion.
Thanks
Samy

Avatar
s_a_m_y

Community Member, 26 Posts

9 March 2011 at 2:12am

Ok, I found a working solution. This might help other beginners, too:

$.noConflict();
jQuery(document).ready(function($){
   $(function()
         {
      $('#Content').jScrollPane({showArrows: true});
         });
});

Avatar
Willr

Forum Moderator, 5513 Posts

9 March 2011 at 10:07pm

That solution seems quite verbose!

You normally just need to wrap your own code in a closure. I use UDF + scrollpane on a couple of my sites..

(function($) {
$(document).ready(function() {

// your code;
})
})(jQuery);

Avatar
s_a_m_y

Community Member, 26 Posts

10 March 2011 at 2:04am

Hi Willr,

thanks for your advise. Your code works well!

Samy