Jump to:

23479 Posts in 18951 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » jQuery conflict with userforms

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: 2192 Views
  • s_a_m_y
    Avatar
    Community Member
    25 Posts

    jQuery conflict with userforms Link to this post

    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

  • s_a_m_y
    Avatar
    Community Member
    25 Posts

    Re: jQuery conflict with userforms Link to this post

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

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

  • Willr
    Avatar
    Forum Moderator
    5502 Posts

    Re: jQuery conflict with userforms Link to this post

    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);

  • s_a_m_y
    Avatar
    Community Member
    25 Posts

    Re: jQuery conflict with userforms Link to this post

    Hi Willr,

    thanks for your advise. Your code works well!

    Samy

    2192 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.