I’m new to Payload and and barely comfortable with React, trying to figure out what a reasonable approach might be for making the Code field’s language something that can be changed on the fly by the content editor.
What I’ve considered:
1. Making a jillion separate Code fields and using a Language select field with a condition to toggle them. (Seems gross.)
2. Creating a custom field that includes the Select and Code fields together. (Got that sort of working, but not sure if I should just serialize an object with
code
and
language
properties for the value or if there’s a better way.)
3. There’s maybe a way to get at component state/props from a field hook and wire things together, but I failed to connect the dots. (
useFormFields
looks promising, but it doesn’t look like it’s meant to be called from a field hook?)
The Color Picker field guide was really helpful, and I have a feeling I’m missing something pretty basic! I’d very much appreciate any high-level guidance!
...and this has been covered. Option 3’s a valid approach if you use it sensibly:
https://payloadcms.com/community-help/discord/use-the-value-from-another-field-inside-a-block✨
Sorry for the noise!
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.