community-forum icon indicating copy to clipboard operation
community-forum copied to clipboard

[Feature Request] Add closure to fields value

Open skpr-repo opened this issue 3 years ago • 3 comments

Feature Request

What's the feature you think Backpack should have?

Fields should accept a closure for the value field, as Columns do. This is very useful for the hidden field or for the custom_html field.

Have you already implemented a prototype solution, for your own project?

I added the same code I found into the Columns components.

if($column['value'] instanceof \Closure) { $column['value'] = $column'value'; }

Do you see this as a core feature or an add-on?

It should be a core feature, it's quite easy to implement.

The aforementioned code is used in every column so it could be embedded into an external blade file and included in every component with the include blade directive.

Thanks

skpr-repo avatar Sep 19 '22 15:09 skpr-repo

@skpr-repo thanks for the suggestion, may I ask for a concrete example ?

In the Create form you can set the field value with: value => 'smt', you have access to the Request etc. In the Update you can still set the value the same way, but you also have access to the entry with: CRUD::getCurrentEntry() so that you can do stuff depending on other entry attributes.

I will be moving this to the Ideas repository where we pick the Feature Requests to work on.

Cheers

pxpm avatar Sep 20 '22 15:09 pxpm

I was in need to add a custom value to a hidden field and to a custom_html field inside a repeater, based on the current row $entry :-)

skpr-repo avatar Sep 20 '22 15:09 skpr-repo

@skpr-repo doesn't JS API help here? https://backpackforlaravel.com/docs/5.x/crud-fields-javascript-api

pxpm avatar Sep 20 '22 15:09 pxpm