James Kenworthy
Dependent Select -> Form Fill Issue
the solutions was a teak to the ->afterStateHyrdated and adding the relationship..
Select::make('location_id')
->label('Location')
->preload()
->relationship(name: 'location', titleAttribute: 'name')
->placeholder(fn (Get $get): string => empty($get('division_id')) ? 'First select division' : 'Select an option')
->required()
->live()
->afterStateHydrated(function (Set $set, Get $get, ?Model $record) {
if ($record) {
$set('location_id', $record->location_id);
Log::info("Location field hydrated with selected value", [
'selected' => $record->location_id,
]);
}
}),
Select::make('resource_id')
->preload()
->relationship(name: 'resource', titleAttribute: 'name')
->label('Resource')
->nullable()
->live()
->afterStateHydrated(function (Set $set, Get $get, ?Model $record) {
if ($record) {
$set('resource_id', $record->resource_id);
Log::info("Resource field hydrated with selected value", [
'selected' => $record->resource_id,
]);
}
}),
4 replies