-
-
Notifications
You must be signed in to change notification settings - Fork 550
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
[5.x] Add parent
keyword to field conditions
#9385
[5.x] Add parent
keyword to field conditions
#9385
Conversation
parent
keyword to field conditionsparent
keyword to field conditions
@jesseleite Can you please take a look at this one?
🤗 |
…d-parent-keyword-to-field-conditions
…`root.` for backwards compat).
…d-parent-keyword-to-field-conditions
…d-parent-keyword-to-field-conditions
… chained `$parent`s.
Didn't anticipate this, but ended up finding issues with the new Sorry @florianbrinkmann @simonerd, this PR turned into a bit of a Ship of Theseus scenario 😅 Anyway, we got there, and I really appreciate your initiative on this and #9960 ❤️ ... Please feel free to test this one out before Jason merges! 🙏 Anyway, I did the following:
|
Thanks a lot @jesseleite! Will give it a try in the next days |
Works like expected 🎉 |
Thanks @jesseleite and thanks @florianbrinkmann for testing. My new future coworker (👨🏻🍼) hasn't allowed me to test this myself yet, but I'm sure my original usecase is resolved with these changes 😇🤓 |
Congrats @simonerd ! |
Congrats @simonerd! 🍼🍾🍼🍾🍼! |
Thanks @jasonvarga @jesseleite It's been 10 months now though. I'm currently on paternity leave, looking after the little one full time 😁 |
Thanks for this welcome addition you all. And ❤️ for your family @simonerd! ps> this feature works like a charm! |
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 statamic/ideas#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.