Silverstripe Version: 4.1
Not sure how to go about representing this relationship in a front end form? I couldn’t see any repeatable type fields or examples.
Relationship in Event data object:
$many_many = [ EventLinks => EventLink::class ];
EventLink object has the opposite with belongs_many_many.
EventLink is just a Title and a Url of a link.
I started off thinking I would make a CompositeField in the Form for the EventLink object, like:
CompositeField::create( TextField::create('WebsiteName')->setName('Links[WebsiteName]'), TextField::create('WebsiteUrl')->setName('Links[WebsiteUrl]') )->setName('Links'),
Used in a form template:
<div id="LinkWrapper"> $Fields.FieldByName('Links') </div> <button id="AddMoreLinks" type="button"">Add more links</button>
And write some JS to clone and copy off an add button.
How are the values populating the form going to work though? In the case of an edit with 5 existing EventLink records?
Is there a better/different way to go about it?