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.

Customising the CMS /

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

Pass parameter to GridField to pre-populate new items


Go to End


2 Posts   1451 Views

Avatar
zard

Community Member, 25 Posts

9 July 2014 at 10:02am

Edited: 09/07/2014 10:04am

Hi,

I am using GridField on a custom form I've created in the front-end. The page I am serving gets a main record ID from the URL and the idea is to then show objects on the page with nice GridField editor.

The main object whose ID is passed via URL parameter has has_many relationship to items I am trying to create using the Gridfield.

This is what I got in terms of Form generation: http://www.sspaste.com/paste/show/53bc6560b45c0
(there is extra layer of indirection as I've got booking requests linked to itineraries but that is not important for the example)

It works great in terms of listing all the elements if I manually specify the relation in the new item dialog, however, how do I automatically pre-fill that field? What happens is that the new element gets loaded on a new page, which loses the ID parameter, therefore I need to select the relation manually if I need it.

How can I dynamically define defaults for newly created GridField objects?

(I am using https://github.com/webbuilders-group/silverstripe-frontendgridfield to facilitate the edits but it is just encapsulation over GF)

Avatar
zard

Community Member, 25 Posts

11 July 2014 at 1:37am

Nobody has ever encountered this?