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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Custom fields - repetively add from CMS


Go to End


4 Posts   998 Views

Avatar
try2dream

Community Member, 5 Posts

15 January 2013 at 3:09pm

Hi,

If i create custom fields, say for a restaurant menu so the client can change the menu as they please, eg:
Dish name
Dish price

Doing it the way in the tutorial, i would have to know how many items are on the clients restaurant menu in order to know how many custom fields to create or i would have to make say 50 so that they never run out.

Is there a way to setup custom fields so that the client has an 'add another row' button which duplicates the fields and the template just cycles through the amount that they have added?

If yes, is there a tutorial on the net for this?

Cheers

Avatar
Willr

Forum Moderator, 5523 Posts

15 January 2013 at 4:24pm

The standard approach for this would be to store your custom field as a dataobject then use a GridField instance to add / edit each new row. http://doc.silverstripe.org/framework/en/tutorials/5-dataobject-relationship-management covers an introduction to relationships.

Avatar
try2dream

Community Member, 5 Posts

15 January 2013 at 4:39pm

Exactly what I was after, thanks!

Is is possible to easily add drag and drop ordering to this type of setup as well?

Avatar
kinglozzer

Community Member, 187 Posts

15 January 2013 at 10:51pm

For drag & drop gridfield ordering I use this:

https://github.com/UndefinedOffset/SortableGridField