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

Adding unlimited repeating fields of the same type


Reply

4 Posts   1218 Views

Avatar
DanStephenson

31 March 2009 at 7:01am (Last edited: 31 March 2009 11:57am), Community Member, 115 Posts

Hi all,

I am looking to build a site, and for one of my templates, the user should be able to post an unlimited number of a certain content type, which in this case is links. For each link, I want the user to be able to add a title, and URL.

Instead of creating say 10 link fields for the client to populate in the CMS, I would like this to be flexible, so the client can have as many of these as they need. Is there a way in the CMS that I can make a "repeating field", so the client can add or remove the elements as needed? If so, can anyone tell me how to go about setting these up?

Avatar
Ben Gribaudo

1 April 2009 at 2:21am Community Member, 181 Posts

Hi Dan,

Sounds like you need to build a link data type having fields URL and title. Then, from your page type, create a one-to-many relationship with the link data type. On your page type, you could use something like DataObjectManager in getCMSFields() to give you a way to create the link entries from the CMS admin interface.

Ben

Avatar
jadedstudio

7 November 2012 at 4:42am Community Member, 5 Posts

Sorry to bump such an old thread but did you ever get this working?

I would like to do this in SilverStripe 3 but as yet haven't found a way.

I can generate extra form fields using jQuery, however it only saves the last field to the Database.

Any help would be really appreciated.

Avatar
zenmonkey

7 December 2012 at 2:33am Community Member, 528 Posts

You need to add that field as its own data object and use a $has_many relation. Then you can use a grid field to manipulate it.