afterStateHydrated behavior within Block builder
I have an TextInput field within a Block, and I would like to fill it with uuid when it's empty. I am doing that:
Forms\Components\TextInput::make('internal')
->afterStateHydrated(function ($component, $state) {
if (! $state) {
$component->state(Str::uuid()->toString());
}
})
->disabled()
->suffixAction(CopyAction::make())
->dehydrateStateUsing(fn ($state) => $state ?? Str::uuid()->toString()),
But it's not working. Any thoughts?5 Replies
Should work. Did you try only this?
maybe just default() ?
that will get filled when the block is created
I am wondering if I will always have the same uuid ?
if its in the livewire state yes
does not change anything. It's strange because $state is null when I add a new block but it seems that $component->state(Str::uuid()->toString()); does nothing