[4.x] Add parent
keyword to field conditions
#9385
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
You can already reference the root level of nested fields by using
root.
at the beginning of a field condition. However, there are cases where it’s not possible to use theroot.
way, because fields are nested multiple times in replicator or grid fields, and one cannot specify the absolute path in the condition, because it’s dynamic (the condition path would need to look something like thatroot.replicator.0.field_handle
if the fieldreplicator_handle.0.grid_handle.3.conditional_field_handle
should be hidden/shown based on the value ofreplicator.0.field_handle
).This PR tries to fix that with adding a
parent.
keyword, that can be added to field conditions, just likeroot.
(as proposed in #783). Unlikeroot.
however,parent.
uses the current field as the reference and goes one level up, making it possible to, for example, reference a field one level higher than a field in a replicator, even if that target field is part of a replicator/grid field again.With that, we can reference the field
replicator.0.field_handle
fromreplicator_handle.0.grid_handle.3.conditional_field_handle
by using the following path:parent.field_handle
things to discuss/to do
parent
, to minimize the chance of crashing existing sites?tests/FieldConditionsValidator.test.js
, but I always got the error thattarget
is null in theStatamic.$conditions.add
callback. I don’t know if theparent
needs to be added somewhere else, or if something other is missing.