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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Customising the CMS /

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

Pre-filled fields in ModelAdmin

Go to End

3 Posts   1218 Views


Community Member, 18 Posts

6 November 2010 at 8:41am


When adding a new entry using ModelAdmin I would like to have a dropdown list that fills out fields automatically on select.

I was thinking the best way to do this was to create a separate DataObject that holds all these "template" objects, and then use jQuery to loop through all the values on select and populate the relevant fields but not sure where to start, so if someone could point me in the right direction I would appreciate it. Ideally, I'd like to add a 'Save as default' button when creating a new record that would then create a new entry that would get added to the dropdown.



Forum Moderator, 1899 Posts

6 November 2010 at 9:19pm

create your dataobject for defaults
using getCMSFields add you new dropdown to select the defaults record on the target dataobject
use the jQuery to add on change of the new dropdown the reads the new records and writes them into the form
create an ajax function for the onchange to call that passes the selection and returns a JSON array of the required values

alternatively you could just add the new dropdown and then put all of the work into onbeforewrite - this could check the value of this one field and then depending on it's value populate everything else before the write


Community Member, 18 Posts

9 November 2010 at 8:02am

The jQuery approach is for sure the most proper but onBeforeWrite sounds like a much quicker fix, didn't think of that so cheers!