Added logic for recently loaded data for lal text input boxes
This commit is contained in:
@@ -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),
|
||||
|
||||
@@ -12,6 +12,17 @@ class CreateQualityValidation extends CreateRecord
|
||||
{
|
||||
protected static string $resource = QualityValidationResource::class;
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
parent::mount();
|
||||
session()->forget([
|
||||
'last_selected_plant_id',
|
||||
'last_selected_line',
|
||||
'last_selected_production',
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
protected function beforeCreate(): void
|
||||
{
|
||||
$errors = [];
|
||||
@@ -93,6 +104,24 @@ class CreateQualityValidation extends CreateRecord
|
||||
}
|
||||
}
|
||||
|
||||
protected function afterCreate(): void
|
||||
{
|
||||
// Get the value from the hidden field 'plant'
|
||||
$plant = $this->form->getState()['plant'] ?? null;
|
||||
$line = $this->form->getState()['line'] ?? null;
|
||||
$production = $this->form->getState()['production'] ?? null;
|
||||
if ($plant) {
|
||||
session(['last_selected_plant_id' => $plant]);
|
||||
}
|
||||
if ($line) {
|
||||
session(['last_selected_line' => $line]);
|
||||
}
|
||||
if ($production) {
|
||||
session(['last_selected_production' => $production]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected function getRedirectUrl(): string
|
||||
{
|
||||
//return $this->getResource()::getUrl('create'); // Stay on Create Page after saving
|
||||
|
||||
Reference in New Issue
Block a user