Jump to:

23007 Posts in 11866 Topics by 2828 members

General Questions

SilverStripe Forums » General Questions » Unable to use javascript in ModelAdmin

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: 227 Views
  • Bereusei
    Avatar
    Community Member
    94 Posts

    Unable to use javascript in ModelAdmin Link to this post

    I´m using SS2.4 with the RemodelAdmin (http://www.leftandmain.com/uncategorized/2011/02/25/taming-the-beast-remodeling-modeladmin/) for the project, I´m working on.

    When you open an entry in RemodelAdmin to edit some values, an javascript should run if you change the value in an inputfield, something like that:

    $('#Form_EditForm_Foo').on('keydown', function(){
    //Do something
    });

    I´ve tried to use in the ModelAdmin class:

    Requirements::javascript('foo/foo.js');


    and the javascript is called correctly and it works perfectly for the search inputfields on the left for example,
    but I can't figure out how to get it works for the right side.

    I know that the javascript is loaded too soon to make things on the right side after I click on an entry,
    but it must be possible to use javascript somehow?

  • Futureweb
    Avatar
    Community Member
    232 Posts

    Re: Unable to use javascript in ModelAdmin Link to this post

    firstly, check the source code to check the js file is actually loading...

    if is it is, you'll need 'entwine' it. The example below is runs when the a custom model is openned... simply put, it waits for a div with the class NameOfMyCustomAdmin' to appear, then adds the javascript.

    you'll have to set it up to connect with

    (function($) {

    $(document).ready(function(){

    $('.NameOfMyCustomAdmin').entwine({
    onmatch: function() {

    // do your stuff

    }
    });

    })

    })(jQuery);

  • Bereusei
    Avatar
    Community Member
    94 Posts

    Re: Unable to use javascript in ModelAdmin Link to this post

    Great, this is it, now it works! Great thanks!

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