document data in groups not accessible in conditional statements in other groups #1891
-
Bug ReportWhen using conditional statements on fields within a group, data from other groups returns undefined causing the application to crash on page load. an example:
The conditional statement on the testField2 field does not evaluate correctly when creating a new document. The conditional statement can access the data when editing existing documents where testField1 is already populated, while it crashes the page when creating a new document Steps to Reproduce
Other DetailsI'm currently running Payload 1.5.8 New document error stack trace:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Additionally, the following code crashes the application on editing existing documents, even if it has the
the field that is causing the crash is |
Beta Was this translation helpful? Give feedback.
-
Hey @ToneseekerMusical — this is actually intended behavior, because when you create a document, there is no data yet. You should write your conditions so that you access those nested properties safely, in case there is no data. For example:
Does that make sense? I will convert this to a discussion so we can keep conversation going. Overall though it's a good practice to safely access nested data in conditions, because of the exact thing you're running into. The data structure might not be there yet! |
Beta Was this translation helpful? Give feedback.
Hey @ToneseekerMusical — this is actually intended behavior, because when you create a document, there is no data yet. You should write your conditions so that you access those nested properties safely, in case there is no data. For example:
Does that make sense? I will convert this to a discussion so we c…