When you open an edit form in Filament, the default
property doesn't work, it only works when creating a new record.
In this case you want to use the afterStateHydrated
property, inject the current form Component
and, in my case, also inject the Get
so that I can get the value of another property:
Forms\Components\TextInput::make('value')
->label(
function(Get $get) {
// setting the label to the name of a different property
return $get('name') . ($get('unit') ? ' (' . $get('unit') . ')' : '');
}
)
->afterStateHydrated(
function (Component $component, Get $get) {
// here I can `Get` the value of some property and set the `state` of the `Component`
$component->state($get('default_value'));
}
)
Bonus: setting the label name to a different value.