Dynamic config based on siblingData #236
Replies: 2 comments 6 replies
-
Would love some extra options to achieve this as well. For I cam up with creating a custom component and then using Payload's React hooks - the hooks you can import from |
Beta Was this translation helpful? Give feedback.
-
I don't think there is a one correct way here. I can see both cases being made depending on the project of either allowing the content authors to make presentational choices in their workflow, or automating content flow decisions for them as you've done. I've done something similar where content blocks in a page are an With your fluid approach of dynamically making layout decisions for authors, I would expect more developer effort as you need to impose the restrictions with min and maxRows, validation and conditions to be sure the content that the editor can create still works within the frontend design system you build. Going this route, I would advise to keep it as simple as you can to avoid endless dev time in validating that the allowed content structures cannot break the presentation in any way. Users always find ways to input the unexpected and they will surely let you know how your tools are "broken". It would be nice if it does work out well, and it could be really powerful. This is a good discussion topic and I'm curious what you decide to do and what others think. |
Beta Was this translation helpful? Give feedback.
-
I have run into a few scenarios where I would love for the config to be dynamic, I may not want to completely hide the field, but instead I would just like to adjust some of its properties.
One example I have is with the following fields config:
The idea here is to disallow the user from selecting a value that does not make sense, without needing to create two separate fields that I show/hide conditionally as this would clean up my api response and front end code a little. So if the user adds 3 images, the
imagePlacement
options would be different that if they were to only add 2 images. I was also thinking this could be done another way (with a similar approach) where you let the user select fromimagePlacement
and then dynamically adjust themedia
array'sminRows
value based on the selected option.For now, I have sidestepped this issued by creating two separate fields and hiding/showing each one based on the number of media elements added.
Anyone else have any use cases? Is there a better approach to something like this?
Beta Was this translation helpful? Give feedback.
All reactions