F
Filament12mo ago
qcol

afterStateHydrated - how to fill in other fields in 'create' mode?

I need to fill in some empty fields when creating a record. Set does not work if operation = create (in edit it works fine).
Solution:
->default() ?
Jump to solution
10 Replies
Solution
LeandroFerreira
LeandroFerreira12mo ago
->default() ?
Yuut4
Yuut412mo ago
can't you use afterStateUpdated(function ($set) { your logic })? I think I already used it in create and it worked normally if I'm not mistaken
qcol
qcol12mo ago
there is also a default... completely forgot about it - thank you! Unfortunately, it doesn't seem to work in the create mode
Yuut4
Yuut412mo ago
do you have ->reactive() on the field you want to change? I had an idea it worked but if not sorry for the confusion
awcodes
awcodes12mo ago
Updated requires reactive. If your just filling it. afterStateHydrated() would be better. But on a create page default() is preferable.
Yuut4
Yuut412mo ago
true xD
qcol
qcol12mo ago
I have ->live(onBlur: true)
Yuut4
Yuut412mo ago
I don't remember needing ->live on filament until now
awcodes
awcodes12mo ago
It replaced reactive() since livewire switched to defer by default. Makes filaments api closer to livewires.
Yuut4
Yuut412mo ago
ok thanks for the explanation