How can we access and change field values programmatically?

default discord avatar
Optiq012 years ago
1 1

I have a field group that I want to toggle on and off with a checkbox. Coming from an Angular background I'm making all my fields as their own individual files to import and orchestrate together where needed so none of their instances of use are hardcoded. How can I listen to the value of the checkbox and dig down into the imported field group and change the 'hidden' property's value accordingly? Is this something we can currently do?

  • Selected Answer
    discord user avatar
    2 years ago

    Hey @Optiq01 — great question!

    There are a lot of ways that this could be accomplished. Firstly, have you seen the Conditional Logic feature yet? Your use case of having a checkbox to toggle a field set on and off is exactly why we built it.

    See this screen capture for a similar implementation:


    Now, this feature only shows and hides field groups. Alternatively, if you need to change the values of existing fields when some other field is modified, then you can use either a field hook, which allows you to set a field's value dynamically based on other field values, or you can create a custom field component and utilize our forms' hooks, which gives you access to both send and receive values of any field in your form, wherever you want.

    Here is another discussion that references this:

    #236 (reply in thread)

    1 reply
  • default discord avatar
    Optiq012 years ago

    Ahhh splendid, and yes I did see that part of the docs however I was confused about how to access a sibling's data and going back and forth between that and the hooks in terms of figuring out how it could be done. I've also been studying the repository and come to dead ends where everything points at your dist folder which isn't publicly available. The docs are excellent but I'm not smart enough for things to be as self explanatory as they might be for others lol. I tinkered around and got it to work but you mentioned there's lots of ways this can be done. What are the others?

Star on GitHub


Chat on Discord



Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.