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')
|
Forms\Components\Select::make('plant_id')
|
||||||
->relationship('plant', 'name')
|
->relationship('plant', 'name')
|
||||||
->reactive()
|
->reactive()
|
||||||
->afterStateUpdated(function (callable $set, callable $get) {
|
->afterStateUpdated(function (callable $set, callable $get, $state) {
|
||||||
$set('item_id', null);
|
$set('item_id', null);
|
||||||
$set('line_id', null);
|
$set('line_id', null);
|
||||||
$set('production_order', null);
|
$set('production_order', null);
|
||||||
|
|
||||||
|
$set('plant', $state);
|
||||||
|
|
||||||
$pId = $get('plant_id');
|
$pId = $get('plant_id');
|
||||||
if (!$pId) {
|
if (!$pId) {
|
||||||
$set('pqPlantError', 'Please select a plant first.');
|
$set('pqPlantError', 'Please select a plant first.');
|
||||||
@@ -69,12 +71,16 @@ class QualityValidationResource extends Resource
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
->required()
|
->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) => [
|
->extraAttributes(fn ($get) => [
|
||||||
'class' => $get('pqPlantError') ? 'border-red-500' : '',
|
'class' => $get('pqPlantError') ? 'border-red-500' : '',
|
||||||
])
|
])
|
||||||
->hint(fn ($get) => $get('pqPlantError') ? $get('pqPlantError') : null)
|
->hint(fn ($get) => $get('pqPlantError') ? $get('pqPlantError') : null)
|
||||||
->hintColor('danger'),
|
->hintColor('danger'),
|
||||||
|
Forms\Components\Hidden::make('plant')
|
||||||
|
->default(fn () => session('last_selected_plant_id')),
|
||||||
|
|
||||||
Forms\Components\Select::make('line_id')
|
Forms\Components\Select::make('line_id')
|
||||||
->relationship('line', titleAttribute: 'name')
|
->relationship('line', titleAttribute: 'name')
|
||||||
->reactive()
|
->reactive()
|
||||||
@@ -91,10 +97,12 @@ class QualityValidationResource extends Resource
|
|||||||
->pluck('name', 'id')
|
->pluck('name', 'id')
|
||||||
->toArray();
|
->toArray();
|
||||||
})
|
})
|
||||||
->afterStateUpdated(function (callable $set, callable $get) {
|
->afterStateUpdated(function (callable $set, callable $get, $state) {
|
||||||
$set('item_id', null);
|
$set('item_id', null);
|
||||||
$set('production_order', null);
|
$set('production_order', null);
|
||||||
|
|
||||||
|
$set('line', $state);
|
||||||
|
|
||||||
$pId = $get('line_id');
|
$pId = $get('line_id');
|
||||||
if (!$pId) {
|
if (!$pId) {
|
||||||
$set('pqLineError', 'Please select a line.');
|
$set('pqLineError', 'Please select a line.');
|
||||||
@@ -102,11 +110,14 @@ class QualityValidationResource extends Resource
|
|||||||
$set('pqLineError', null);
|
$set('pqLineError', null);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
->default(fn ($get) => $get('line') ?? session('last_selected_line'))
|
||||||
->extraAttributes(fn ($get) => [
|
->extraAttributes(fn ($get) => [
|
||||||
'class' => $get('pqLineError') ? 'border-red-500' : '',
|
'class' => $get('pqLineError') ? 'border-red-500' : '',
|
||||||
])
|
])
|
||||||
->hint(fn ($get) => $get('pqLineError') ? $get('pqLineError') : null)
|
->hint(fn ($get) => $get('pqLineError') ? $get('pqLineError') : null)
|
||||||
->hintColor('danger'),
|
->hintColor('danger'),
|
||||||
|
Forms\Components\Hidden::make('line')
|
||||||
|
->default(fn () => session('last_selected_line')),
|
||||||
Forms\Components\Hidden::make('sticker_master_id')
|
Forms\Components\Hidden::make('sticker_master_id')
|
||||||
// ->relationship('stickerMaster', 'id')
|
// ->relationship('stickerMaster', 'id')
|
||||||
->required(),
|
->required(),
|
||||||
@@ -133,9 +144,11 @@ class QualityValidationResource extends Resource
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
$set('productionError', null);
|
$set('productionError', null);
|
||||||
|
$set('production', $state);
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
|
->default(fn ($get) => $get('production') ?? session('last_selected_production'))
|
||||||
->extraAttributes(fn ($get) => [
|
->extraAttributes(fn ($get) => [
|
||||||
'class' => $get('productionError') ? 'border-red-500' : '',
|
'class' => $get('productionError') ? 'border-red-500' : '',
|
||||||
])
|
])
|
||||||
@@ -143,6 +156,9 @@ class QualityValidationResource extends Resource
|
|||||||
->hintColor('danger')
|
->hintColor('danger')
|
||||||
->required(),
|
->required(),
|
||||||
|
|
||||||
|
Forms\Components\Hidden::make('production')
|
||||||
|
->default(fn () => session('last_selected_production')),
|
||||||
|
|
||||||
Forms\Components\Hidden::make('operator_id')
|
Forms\Components\Hidden::make('operator_id')
|
||||||
->required()
|
->required()
|
||||||
->default(Filament::auth()->user()->name),
|
->default(Filament::auth()->user()->name),
|
||||||
|
|||||||
@@ -12,6 +12,17 @@ class CreateQualityValidation extends CreateRecord
|
|||||||
{
|
{
|
||||||
protected static string $resource = QualityValidationResource::class;
|
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
|
protected function beforeCreate(): void
|
||||||
{
|
{
|
||||||
$errors = [];
|
$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
|
protected function getRedirectUrl(): string
|
||||||
{
|
{
|
||||||
//return $this->getResource()::getUrl('create'); // Stay on Create Page after saving
|
//return $this->getResource()::getUrl('create'); // Stay on Create Page after saving
|
||||||
|
|||||||
Reference in New Issue
Block a user