Is there any simple way to pre-fill the create form in the admin panel when creating a new doc? I've seen you can somehow solve it with a custom component, but I'm wondering if there is no better way, like a custom hook for the admin panel (similar to beforeDuplicate)
I was quite surprised I couldn't find anything about it, since it seems to me that this is quite a common thing to do?
Does setting a default value fulfill your needs?https://payloadcms.com/docs/fields/overview#default-values
Unfortunately not. I have a collection "registrations" and a collection "companies". When a registration arrives, a company should either be linked or created. It can't be fully automated because registrations rely on user Input, so the way I'd solve it is to provide a relationship field in the registration to either link or create a company.
For that to work though, the company info needs to be pre-filled with the data from the registration fields.
Hmmm...I dont have full oversight on your data structure butmaybe
you could put something together using a mix of
functions on fields and
functions to hide other fields until the relationship one is fulfilled
However, for the smoothest UX, custom components would help a lot
that way you can also streamline the process
hmm, such a pity. It's not a huge deal to write a custom component, but I just hate overcomplicating things, since the default functionality would be perfect (apart from the pre fill part)
I would love to weigh in here but am having trouble following. Any way your could throw together a repo and link it here? Even if it’s simplified from your use case
Hey @jarrod_not_jared , sorry for the late reply. I could create a demo repo if really necessary, but the functionality I'm looking for is pretty simple: Prefill certain fields in the Create Form.
Example: I have a collection of Companies, and a collection of Contacts. Every contact belongs to a company and has a relationship field that links to it. Now, I want to add a "create Contact" Button to the Company Edit Page. This is straight forward using a Custom Field component, however, the relationship field in the new contact should be automatically set to the comopany that I'm coming from
Hey @sandrowegmann how did you get on with this?
Got it solved! Was planning to create a video explaining how I achieved it
For the record, Issue solved, I've created a video explaining how I did it: