Bug description
Note: This is probably more a feature request but also it makes custom conditions unusable for linked fields.
If you have a fieldset with a custom condition and you link that fieldset with a prefix there isn't a way for you to know dynamically what the prefix is.
Here is the following diagram to better explain it:
Inside the blueprint, two validations will run and the values parameter will return an object with first_my_field and second_my_field. The problem is you are not aware of what field the validation is running, you don't know the prefix, therefore, you can't write a rule that is only scoped to my_fieldset.
In the ideal scenario, you would have a prefix and you could use it to craft a dynamic condition. For example:
Statamic.$conditions.add("shouldShow", ({ values }) => {
const fieldPrefix = values.prefix
return values[`${fieldPrefix}my_field`] === "something";
});
The function above would only validate in the context of that exact linked field.
The use case for this is: imagine that you have multiple fields inside my_fieldset and you need only fields inside that fieldset to affect the choice. This is the same behavior that the UI filters use, they only apply scoped to the linked field.
How to reproduce
- Create a new fieldset
my_fieldset
- Inside the fieldset create a new field (type not relevant),
my_field
- Set a custom method passes condition on
my_field, let the value by shouldShow
- Create a new collection/blueprint
pages
- Add two linked fieldsets fields
my_fieldset and set a different prefix for both
- Now when you open to create a new
pages collection you will get two validations with the same values
Logs
No response
Environment
Environment
Application Name: Statamic
Laravel Version: 10.14.1
PHP Version: 8.2.3
Composer Version: 2.5.8
Environment: local
Debug Mode: ENABLED
URL: dummy-statamic.ddev.site
Maintenance Mode: OFF
Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: CACHED
Drivers
Broadcasting: log
Cache: statamic
Database: mysql
Logs: stack / single
Mail: smtp
Queue: sync
Session: file
Statamic
Addons: 0
Antlers: runtime
Stache Watcher: Enabled
Static Caching: Disabled
Version: 4.9.2 Solo
Installation
Fresh statamic/statamic site via CLI
Antlers Parser
regex (default)
Additional details
No response
Bug description
Note: This is probably more a feature request but also it makes custom conditions unusable for linked fields.
If you have a fieldset with a custom condition and you link that fieldset with a prefix there isn't a way for you to know dynamically what the prefix is.
Here is the following diagram to better explain it:
Inside the blueprint, two validations will run and the
valuesparameter will return an object withfirst_my_fieldandsecond_my_field. The problem is you are not aware of what field the validation is running, you don't know the prefix, therefore, you can't write a rule that is only scoped tomy_fieldset.In the ideal scenario, you would have a prefix and you could use it to craft a dynamic condition. For example:
The function above would only validate in the context of that exact linked field.
The use case for this is: imagine that you have multiple fields inside
my_fieldsetand you need only fields inside that fieldset to affect the choice. This is the same behavior that the UI filters use, they only apply scoped to the linked field.How to reproduce
my_fieldsetmy_fieldmy_field, let the value byshouldShowpagesmy_fieldsetand set a different prefix for bothpagescollection you will get two validations with the samevaluesLogs
No response
Environment
Installation
Fresh statamic/statamic site via CLI
Antlers Parser
regex (default)
Additional details
No response