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.

Customising the CMS /

Pre-filled fields in ModelAdmin


Reply


3 Posts   920 Views

Avatar
beezer

Community Member, 16 Posts

6 November 2010 at 8:41am

Hi,

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.

Cheers

Avatar
swaiba

Forum Moderator, 1799 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

Avatar
beezer

Community Member, 16 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!