Added logic for recently loaded data for lal text input boxes

This commit is contained in:
dhanabalan
2025-06-03 12:56:43 +05:30
parent 22b653fc03
commit ce4f9d7246
2 changed files with 48 additions and 3 deletions

View File

@@ -51,11 +51,13 @@ class QualityValidationResource extends Resource
Forms\Components\Select::make('plant_id')
->relationship('plant', 'name')
->reactive()
->afterStateUpdated(function (callable $set, callable $get) {
->afterStateUpdated(function (callable $set, callable $get, $state) {
$set('item_id', null);
$set('line_id', null);
$set('production_order', null);
$set('plant', $state);
$pId = $get('plant_id');
if (!$pId) {
$set('pqPlantError', 'Please select a plant first.');
@@ -69,12 +71,16 @@ class QualityValidationResource extends Resource
}
})
->required()
->default(fn () => request()->query('plant_id'))
//->default(fn () => request()->query('plant_id'))
->default(fn ($get) => $get('plant') ?? session('last_selected_plant_id'))
->extraAttributes(fn ($get) => [
'class' => $get('pqPlantError') ? 'border-red-500' : '',
])
->hint(fn ($get) => $get('pqPlantError') ? $get('pqPlantError') : null)
->hintColor('danger'),
Forms\Components\Hidden::make('plant')
->default(fn () => session('last_selected_plant_id')),
Forms\Components\Select::make('line_id')
->relationship('line', titleAttribute: 'name')
->reactive()
@@ -91,10 +97,12 @@ class QualityValidationResource extends Resource
->pluck('name', 'id')
->toArray();
})
->afterStateUpdated(function (callable $set, callable $get) {
->afterStateUpdated(function (callable $set, callable $get, $state) {
$set('item_id', null);
$set('production_order', null);
$set('line', $state);
$pId = $get('line_id');
if (!$pId) {
$set('pqLineError', 'Please select a line.');
@@ -102,11 +110,14 @@ class QualityValidationResource extends Resource
$set('pqLineError', null);
}
})
->default(fn ($get) => $get('line') ?? session('last_selected_line'))
->extraAttributes(fn ($get) => [
'class' => $get('pqLineError') ? 'border-red-500' : '',
])
->hint(fn ($get) => $get('pqLineError') ? $get('pqLineError') : null)
->hintColor('danger'),
Forms\Components\Hidden::make('line')
->default(fn () => session('last_selected_line')),
Forms\Components\Hidden::make('sticker_master_id')
// ->relationship('stickerMaster', 'id')
->required(),
@@ -133,9 +144,11 @@ class QualityValidationResource extends Resource
else
{
$set('productionError', null);
$set('production', $state);
}
})
->default(fn ($get) => $get('production') ?? session('last_selected_production'))
->extraAttributes(fn ($get) => [
'class' => $get('productionError') ? 'border-red-500' : '',
])
@@ -143,6 +156,9 @@ class QualityValidationResource extends Resource
->hintColor('danger')
->required(),
Forms\Components\Hidden::make('production')
->default(fn () => session('last_selected_production')),
Forms\Components\Hidden::make('operator_id')
->required()
->default(Filament::auth()->user()->name),