Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes to hidden fields via hooks are not persisted #9043

Closed
elliott-w opened this issue Nov 6, 2024 · 3 comments
Closed

Changes to hidden fields via hooks are not persisted #9043

elliott-w opened this issue Nov 6, 2024 · 3 comments
Labels

Comments

@elliott-w
Copy link

elliott-w commented Nov 6, 2024

Describe the Bug

See title

Link to the code that reproduces this issue

https://github.com/elliott-w/payload

Reproduction Steps

Add the following field to any collection:

{
  name: 'test',
  type: 'checkbox',
  defaultValue: false,
  hidden: true,
  hooks: {
    beforeChange: [
      () => {
        return true
      },
    ],
    afterChange: [
      ({ value }) => {
        console.log(`------- ${value} -------`)
      },
    ],
  },
},

In the repro, I've added this to the posts collection.

When you create a post you would expect true to be printed in console, but you get false

Change hidden property to false and now you get true printed in console.

Which area(s) are affected? (Select all that apply)

area: core

Environment Info

Binaries:
Node: 20.16.0
npm: 10.8.1
Yarn: N/A
pnpm: 9.12.2
Relevant Packages:
payload: 3.0.0-beta.124
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 23.6.0: Mon Jul 29 21:13:04 PDT 2024; root:xnu-10063.141.2~1/RELEASE_ARM64_T6020
Available memory (MB): 16384
Available CPU cores: 10

@elliott-w elliott-w added status: needs-triage Possible bug which hasn't been reproduced yet v3 validate-reproduction labels Nov 6, 2024
@jmikrut
Copy link
Member

jmikrut commented Nov 6, 2024

Hey @elliott-w — this is by design, as by default, hidden fields are completely omitted before afterChange hooks are run. They would appear if you had run a local API update or create with showHiddenFields: true, but because the REST API and GraphQL APIs do not have a way to expose hidden fields, they will indeed be hidden in lots of cases.

If you would like to have your hidden field return from APIs and be visible in afterChange hooks, but hide them only in the admin UI, you could use admin.hidden or admin.disabled instead. Either of these options would make them surface in the afterChange hook but stay hidden in the admin UI.

@jmikrut jmikrut closed this as completed Nov 6, 2024
@github-actions github-actions bot removed the status: needs-triage Possible bug which hasn't been reproduced yet label Nov 6, 2024
@elliott-w
Copy link
Author

@jmikrut Thanks for the detailed response!

Copy link

github-actions bot commented Nov 8, 2024

This issue has been automatically locked.
Please open a new issue if this issue persists with any additional detail.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants