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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

How to make children movable?


Go to End


7 Posts   1060 Views

Avatar
cybesun

Community Member, 9 Posts

11 August 2014 at 6:23am

Hi All,

I've a DataObject ClassRoom which has a many Students. Each student can only be assigned to one ClassRoom.

I've a ModelAdmin for the ClassRoom objects.

Now I'd like to move one Stundent form one ClassRoom to another.

I'd like to do that with making the parent ClassRoomID in the Stunden data object editable.

I tried to make the parent id editable - but that doesn't work.

Thanks for your help.

Avatar
Kirk

Community Member, 67 Posts

11 August 2014 at 2:40pm

If I was going to to do something like this I would have a has_one for the ClassRoom on the Student model and override getCMSFields to add a new dropdown field for the classroom

        public function getCMSFields() {
                $fields = parent::getCMSFields();
                $fields->push(new DropdownField('ClassRoom', 'Select Class room', ClassRoom::get());
                return $fields;
        }

Avatar
cybesun

Community Member, 9 Posts

12 August 2014 at 6:28am

I tried that, but doesn't work.

What happens is, if I change the id and press save - nothing happens. The id is automatically resetted to the old one.

Somehow it seems that I cannot change a parent id?

Avatar
Kirk

Community Member, 67 Posts

12 August 2014 at 9:23am

What are you using for the name for the classroom it should be ClassRoomID (or whatever the name is in the the DB) in the example I posted I put ClassRoom when it should have probably been ClassRoomID

Avatar
cybesun

Community Member, 9 Posts

13 August 2014 at 7:01am

Doesn't seem to work. ( with ClassRoomID and ClassRoom )

Here is the code I'm using: https://gist.github.com/kiruSan/341d0e7761237b4a80ea

Do you have another idea?

Thanks for your help!

Avatar
Kirk

Community Member, 67 Posts

13 August 2014 at 9:06am

Tried your code on a fresh install and it works from the ClassRoom model admin.
When I go into the ClassRoom Model admin next to the main tab I have a student tab where I can link existing students to a classroom.
I am using a 3.1 install

Avatar
cybesun

Community Member, 9 Posts

7 September 2014 at 12:45am

Edited: 07/09/2014 12:46am

It does work with the link-existing tool.

But my use case is, that I want to go within the class room, select one student and on the student level I should be able to move him to another classroom.

Like this: http://screenpresso.com/=s4Grb