CodeWithDennis / filament-select-tree

The multi-level select field lets you pick one or multiple options from a list that is neatly organized into different levels.
MIT License
207 stars 28 forks source link

How to use afterStateUpdated? #31

Closed 0528Makoto closed 10 months ago

0528Makoto commented 11 months ago

How to use afterStateUpdated in SelectTree?

in Select

->afterStateUpdated(fn (string $operation, Forms\Components\Select $component, Forms\Set $set) => 'create' === $operation ? $set('name_alias', $component->getOptionLabel()) : null)

but this method "getOptionLabel" no exist in SelectTree

CodeWithDennis commented 11 months ago

The SelectTree is not a select field so you cant really do this.

0528Makoto commented 11 months ago

How could I obtain the "name" of the selected option or options?

CodeWithDennis commented 11 months ago

Right now, it's not officially supported, but you could try something like this:

->afterStateUpdated(function (string $operation, SelectTree $component, $state) {
   // If it's a single select: Category::find($state);
   // For multi-select: Category::whereIn('id', $state)->get();
}),

I'll check if we can make this officially supported down the road