#Auto fill read-only fields from an entity by filling another field with the consequent relationship.

3 messages · Page 1 of 1 (latest)

frozen obsidian
#

Imagine I have a Collection called Users, with the fields Name(text) and Products(relationTo='products') (read-only).
And I also have a collection named Products with the fields Name (text) and Consumers(relationTo='users').

Is it possible to auto fill the read-only products fields in the users collection by providing this information in the Consumers field of the Products collection?

Thanks in advance

frozen obsidian
#

You can use hooks to fill out the read-only field. To manipulate other collections, you can use the locale API.

south flume
#

Hi @frozen obsidian! As @frozen obsidian said, yes you can absolutely achieve this using field / collection hooks.

Here is an example where we use hooks to populate fields: https://github.com/payloadcms/payload/blob/master/examples/virtual-fields/src/collections/Location.ts

And hooks documentation: https://payloadcms.com/docs/hooks/overview#hooks-overview

GitHub

Built with React + TypeScript, Payload is a free and open-source Headless CMS. [✩Star] if you support our work! - payload/Location.ts at master · payloadcms/payload

Payload CMS

Payload is a headless CMS and application framework built with TypeScript, Node.js, React and MongoDB