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 insert a button like GridFieldAddNewButton in Member Form


Go to End


4 Posts   1191 Views

Avatar
Myrdhin

Community Member, 70 Posts

29 January 2015 at 10:29pm

Hello,

I have a DataObject like this:

class MyDataObject extends DataObject {
    private static $db = array( ...  );
    private static $many_many = array(
        'Members' => 'Member'
    );
}

I manage MyDataObject with ModelAdmin. No problem.

I've make an extension:

class MyDataObjectRole extends DataExtension {
    private static $db = array( ... );
    private static $belongs_many_many = array(
        'MyDataObjects' => 'MyDataObject'
    );

    public function updateCMSFields(FieldList $fields) {
        $fields->removeByName('MyDataObjects');

        $mydataobjects = MyDataObject::get()->map('ID', ... );
        $mydataobjectfield = new ListboxField('MyDataObjects', 'MyDataObjects', $mydataobjects);
        $mydataobjectfield->setMultiple(true);

        $fields->addFieldToTab('Root.Main', $mydataobjectfield);
        return $fields;
    }
}

And i use it:

---
Name: extensions
---
Member:
  extensions:
    ['MyDataObjectRole']

In my admin Member form, i see the ListboxField and it works. OK.

But i would like to append a button like GridFieldAddNewButton after my ListbofField to facilitate new MyDataObject creation without going to ModelAdmin.

And i'm lost :)
Somebody can help me ? Thanks

Avatar
martimiz

Forum Moderator, 1391 Posts

30 January 2015 at 1:37am

Could you not use a GridField in stead of a ListBoxField? In a separate tab for instance?

Avatar
Myrdhin

Community Member, 70 Posts

30 January 2015 at 9:31am

Thanks for your proposal but I would like something simple, lighter than a 'big' GridField. I just need to select zero, one or more MyDataObjects. It's OK with the ListboxField. And, with a simple button, I just need to create a new MyDataObject if the object does not exist to link it to the edited or created member.

Avatar
Myrdhin

Community Member, 70 Posts

2 February 2015 at 11:45am

I found an extension : https://github.com/sheadawson/silverstripe-quickaddnew. I don't like the use of a popup but it works :)