statamic / ideas

💡Discussions on ideas and feature requests for Statamic
https://statamic.dev
31 stars 1 forks source link

Computed fields inside a Grid? #889

Open duncanmcclean opened 1 year ago

duncanmcclean commented 1 year ago

Thanks so much for the new Computed Fields feature - I can think of a dozen use cases for it across my different sites.

Currently, I have something similar-ish using custom hidden fieldtypes in one of my addons which I'm aiming to replace with this feature.

However, some of them are computed fields inside a Grid field.... I have a Grid field called 'Line Items' and inside that I have the product, price, etc. If I wanted to make two new computed fields on each line item (like tax_price or raw_price), I don't currently see a way of doing it...

I've tried these two options, neither work.

Collection::computed('orders', 'line_items.raw_price.', function ($entry, $value) {
    return 'something here';
});

Collection::computed('orders', 'line_items.*.raw_price.', function ($entry, $value) {
    return 'something here';
});
jesseleite commented 1 year ago

It's a top level data feature at the moment, not specific to any fieldtype.