From f000821240a41d015d55f1f3454759359f4f06a6 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Fri, 13 Nov 2026 16:19:04 +0530 Subject: [PATCH] Added logic in quality validation for sfg line enter prevent logic --- .../Resources/QualityValidationResource.php | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/app/Filament/Resources/QualityValidationResource.php b/app/Filament/Resources/QualityValidationResource.php index ebee2eb5..095764d7 100644 --- a/app/Filament/Resources/QualityValidationResource.php +++ b/app/Filament/Resources/QualityValidationResource.php @@ -223,7 +223,7 @@ class QualityValidationResource extends Resource ->required() ->autofocus() ->live() - ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + ->afterStateUpdated(function (callable $set, callable $get, ?string $state, $livewire) { $pId = $get('line_id'); $set('part_validation_type', null); @@ -533,6 +533,8 @@ class QualityValidationResource extends Resource $serialAssigned = false; + $visibleSerialColumns = []; + foreach ($serialFields as $column) { $colFld = $column; @@ -548,6 +550,10 @@ class QualityValidationResource extends Resource $set($column . '_visible', $count > 0); + if ($count > 0) { + $visibleSerialColumns[] = $column; // NEW + } + // assign serial only once if (!$serialAssigned && $count > 0) { @@ -608,11 +614,38 @@ class QualityValidationResource extends Resource // Save options in hidden field $set('part_validation_type_options', $options); + $visiblePartValidations = array_filter( + $partValidationColumns, + fn ($col) => ! empty($stickerMaster->$col) + ); + + if ( + $visibleSerialColumns === ['serial_number_motor_qr'] + && (int) $stickerMaster->serial_number_motor === 1 + && empty($visiblePartValidations) + ) { + $livewire->create(); + $livewire->js("document.getElementById('item_id')?.focus()"); + } + }) ->extraAttributes(fn ($get) => [ 'class' => $get('validationError') ? 'border-red-500' : '', 'id' => 'item_id', 'onkeydown' => "if (event.key === 'Enter') { event.preventDefault(); event.stopPropagation(); return false; }", + // 'onkeydown' => " + // if (event.key === 'Enter') { + // if ( + // document.querySelector('[name=\"data[serial_number_motor_qr]\"]')?.value === '1' + // ) { + // this.closest('form').querySelector('button[wire\\\\:click*=\"create\"]')?.click(); + // } else { + // event.preventDefault(); + // event.stopPropagation(); + // return false; + // } + // } + // ", ]) // ->extraAttributes(fn ($get) => [ // 'class' => $get('validationError') ? 'border-red-500' : '',