Jump to:

5542 Posts in 1739 Topics by 1225 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Pre-filled fields in ModelAdmin

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

Page: 1
Go to End
Author Topic: 876 Views
  • beezer
    Avatar
    Community Member
    16 Posts

    Pre-filled fields in ModelAdmin Link to this post

    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

  • swaiba
    Avatar
    Forum Moderator
    1792 Posts

    Re: Pre-filled fields in ModelAdmin Link to this post

    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

  • beezer
    Avatar
    Community Member
    16 Posts

    Re: Pre-filled fields in ModelAdmin Link to this post

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

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