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

[4.x] Add parent keyword to field conditions #9385

Open
wants to merge 2 commits into
base: 4.x
Choose a base branch
from

Conversation

florianbrinkmann
Copy link

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 the root. 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 that root.replicator.0.field_handle if the field replicator_handle.0.grid_handle.3.conditional_field_handle should be hidden/shown based on the value of replicator.0.field_handle).

This PR tries to fix that with adding a parent. keyword, that can be added to field conditions, just like root. (as proposed in #783). Unlike root. 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 from replicator_handle.0.grid_handle.3.conditional_field_handle by using the following path: parent.field_handle

things to discuss/to do

  • should we maybe use something more unique than parent, to minimize the chance of crashing existing sites?
  • I added tests and tried to also extend the »it can call a custom function on a specific field using params against a root value« test in tests/FieldConditionsValidator.test.js, but I always got the error that target is null in the Statamic.$conditions.add callback. I don’t know if the parent needs to be added somewhere else, or if something other is missing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant