Jump to:

23483 Posts in 18965 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » jquery

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: 331 Views
  • Adman
    Community Member
    5 Posts

    jquery Link to this post

    Hi guys,

    I'd like to get custom jQuery working with my silverstripe install. I'm making a tenders class and want to do a bit of custom form field validation, but before I can do that I need to get the requires working and then my code inside the $(document).ready function working.

    Here's what I have in my TenderHolder.php file

    class TenderHolder_Controller extends Page_Controller {

    public function init() {

       Requirements::javascript ('mysite/javascript/jquery-latest.js');
       Requirements::javascript ('mysite/javascript/test.js');



    And here's what I have in my test.js file.

    (function($) {
    // your code here.

    I've also tried this for the test.js file

    $(document).ready(function() {

    alert('hello world');


    I know the requires are working because if I don't surround the alert in jQuery document ready tags then it'll make an alert appear.

    Any ideas would be great appreciated!


  • feejin
    Community Member
    22 Posts

    Re: jquery Link to this post

    I'm guessing that because it works without the jquery code, it's not loading jquery.

    Requirements won't write the script tag in if the file doesn't exist so check the source, are there two <script> tags for your JS files near the bottom of the page?

    If it is outputting them, check your JS console for errors, easily done with Web Developer in Firefox.

    I always store JS files in themes/{name-of-theme} though I'm not sure if this was something I was told to do or just my preference. Can't see it would make a difference though.

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.