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 /

Pass parameter to GridField to pre-populate new items


Reply


2 Posts   327 Views

Avatar
zard

Community Member, 24 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: [url]http://www.sspaste.com/paste/show/53bc6560b45c0[/url]
(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 [url]https://github.com/webbuilders-group/silverstripe-frontendgridfield[/url] to facilitate the edits but it is just encapsulation over GF)

Avatar
zard

Community Member, 24 Posts

11 July 2014 at 1:37am

Nobody has ever encountered this?