Jump to:

23453 Posts in 18902 Topics by 2877 members

General Questions

SilverStripe Forums » General Questions » Ajax requests inside admin section

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: 452 Views
  • folibis
    Avatar
    Community Member
    10 Posts

    Ajax requests inside admin section Link to this post

    Hi All
    My question is about admin section. I have a custom page with set of fields. One of them is «Tags» with many-to_many relation. So I have list with my tags and I can select a few of them without problem. But also I need to add new tag without reloading the page. I guess Ajax is good for this. I am familiar with Ajax, Javascript, PHP but I have no idea how to do that with Silverstripe.

  • folibis
    Avatar
    Community Member
    10 Posts

    Re: Ajax requests inside admin section Link to this post

    The night gone but i sttill search for way to do that.
    Is there any tutorial or doc how Silverstripe build his path to objects?
    I mean, for example, if I edit my page of type ArticlePage with path /admin/pages/edit/show/7 so how can I access controller of this page rather function GetList() from this controller?

  • LoFonz
    Avatar
    Community Member
    4 Posts

    Re: Ajax requests inside admin section Link to this post

    yop.

    Not sure the thread is still up, but basically, to run an ajax request in SS3, this is how I did :

    Include your JS in the "getCMSFields" function of your controller :

    class MyController extends Page{
    public function getCMSFields() {
    Requirements::javascript('mysite/javascript/javascript.js');
    }
    }

    This file will be loaded on pages of type "MyControrller".

    In the javascript.js (that's an example. I call an ajax request everytime I change the value of a dropdownfield) :

    jQuery(document).ready(function($) {
       $.entwine('ss', function($){
          $("#Form_EditForm_MarqueID").entwine({
             onchange : function() {
                //alert(this.val());
                $.ajax({
                   url: '/mysite.be/myadmin/getModels?marqueid='+this.val(), //mysite.be refers to your website of course.
                   type:'GET',
                   success: function(){
                      console.log('it worked);
                   },
                   error: function(){
                      console.log('it failed');
                   }
                });
             }
          });
       });
    });

    I hope I answered your question.

    EDIT : I found a usefull thread, even if it's old, I think it can be useful http://www.silverstripe.org/customising-the-cms/show/7893

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