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
LeandroFerreira
Should work. Did you try only this?
Forms\Components\TextInput::make('internal')
->afterStateHydrated(function (TextInput $component, $state) {
if (blank($state)) {
$component->state(Str::uuid()->toString());
}
})
Forms\Components\TextInput::make('internal')
->afterStateHydrated(function (TextInput $component, $state) {
if (blank($state)) {
$component->state(Str::uuid()->toString());
}
})
Dan Harrin
Dan Harrin2y ago
maybe just default() ? that will get filled when the block is created
David Vincent
David VincentOP2y ago
I am wondering if I will always have the same uuid ?
Dan Harrin
Dan Harrin2y ago
if its in the livewire state yes
David Vincent
David VincentOP2y ago
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
Want results from more Discord servers?
Add your server