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

field.admin.condition data attribute missing document ID when document is being edited #10379

Open
franciscolourenco opened this issue Jan 6, 2025 · 2 comments

Comments

@franciscolourenco
Copy link
Contributor

franciscolourenco commented Jan 6, 2025

Describe the Bug

The data attribute passed to field.admin.condition functions is missing the document ID when the function is executed in the context of formData changes, but not when the document is loaded. This is a breaking change at least from v2.

Link to the code that reproduces this issue

https://github.com/payloadcms/payload/compare/franciscolourenco:reproduce-condition-missing-document-id

Reproduction Steps

Check included e2e test

  1. Use a field.admin.condition function that relies on the document ID (eg. (data) => data.id)
  2. Verify that data.id is defined when the document is loaded, but undefined after any changes are made to the document, until the document is saved again.

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

area: ui

Environment Info

Payload: 3.14.0
Node: 22.8.0
Next: 15.1.3
@franciscolourenco franciscolourenco added status: needs-triage Possible bug which hasn't been reproduced yet validate-reproduction labels Jan 6, 2025
@franciscolourenco franciscolourenco changed the title admin.condition data attribute missing document ID when document is being edited field.admin.condition data attribute missing document ID when document is being edited Jan 6, 2025
@akhrarovsaid
Copy link
Contributor

I've reproduced this one on my end.

However:

Verify that data.id is undefined when the document is loaded, but not after any changes are made to the document, until the document is saved again.

I'm seeing the opposite behavior where data.id is defined initially but then becomes undefined immediately following a field change.

I've found a really simple "fix" here that passes the test you've defined in the repro by adding a check if fullData.id doesn't exist and the id passed to iterateFields does exist, then simply adding it.

if (!fullData.id && typeof id !== 'undefined') {
  fullData.id = id
}

Near the top of this iterateFields function before the loop that checks for passing conditions. However, I don't think this is the real fix here but merely a band-aid.

@franciscolourenco
Copy link
Contributor Author

I'm seeing the opposite behavior where data.id is defined initially but then becomes undefined immediately following a field change.

Yes, that is what I mean, it was a typo 👍

@jacobsfletch jacobsfletch self-assigned this Jan 12, 2025
@github-actions github-actions bot removed the status: needs-triage Possible bug which hasn't been reproduced yet label Jan 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants