Updated item code validation logic
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 16s
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 16s
This commit is contained in:
@@ -14,6 +14,8 @@ use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Forms\Get;
|
||||
use Filament\Forms\Set;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Actions\ExportAction;
|
||||
@@ -21,8 +23,6 @@ use Filament\Tables\Filters\Filter;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Filament\Forms\Set;
|
||||
use Filament\Notifications\Notification;
|
||||
|
||||
class LeakTestReadingResource extends Resource
|
||||
{
|
||||
@@ -85,77 +85,53 @@ class LeakTestReadingResource extends Resource
|
||||
// ->minLength(6)
|
||||
->reactive()
|
||||
->disabled(fn (Get $get) => ! empty($get('id')) && ! Filament::auth()->user()->hasRole('Super Admin'))
|
||||
// ->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
// $code = $get('item_code');
|
||||
// $set('lsrCodeError', null);
|
||||
// if (! $code) {
|
||||
// $set('lsrCodeError', 'Scan the valid item code.');
|
||||
|
||||
// return;
|
||||
// } else {
|
||||
// if (strlen($code) < 6) {
|
||||
// $set('lsrCodeError', 'Item code must be at least 6 digits.');
|
||||
|
||||
// return;
|
||||
// } elseif (! ctype_alnum($code)) {
|
||||
// $set('item_code', null);
|
||||
// $set('lsrCodeError', 'Item code must contain only alpha-numeric characters!');
|
||||
|
||||
// return;
|
||||
// } elseif (! preg_match('/^[a-zA-Z1-9][a-zA-Z0-9]{5,}$/', $code)) {
|
||||
// $set('item_code', null);
|
||||
// $set('lsrCodeError', "Item code should not begin with '0' or letter!");
|
||||
|
||||
// return;
|
||||
// }
|
||||
// $set('lsrCodeError', null);
|
||||
// }
|
||||
// })
|
||||
->afterStateUpdated(function ($state, Set $set, Get $get, $livewire) {
|
||||
if (blank($state)) {
|
||||
$set('item_code', null);
|
||||
$set('serial_number', null);
|
||||
return;
|
||||
}
|
||||
if (blank($state)) {
|
||||
$set('item_code', null);
|
||||
$set('serial_number', null);
|
||||
|
||||
$parts = explode('|', trim($state));
|
||||
return;
|
||||
}
|
||||
|
||||
$parts = explode('|', trim($state));
|
||||
|
||||
if (! preg_match('/^[^|]+\|[^|]+\|?$/', trim($state))) {
|
||||
Notification::make()
|
||||
->title('Invalid QR Format')
|
||||
->body("Expected format: ItemCode|SerialNumber<br>Received Format '$state'")
|
||||
->danger()
|
||||
->send();
|
||||
$set('item_code', null);
|
||||
|
||||
return;
|
||||
} else {
|
||||
$iCode = $parts[0];
|
||||
if (strlen($parts[0]) < 6) {
|
||||
|
||||
if (! preg_match('/^[^|]+\|[^|]+\|?$/', trim($state))) {
|
||||
Notification::make()
|
||||
->title('Invalid QR Format')
|
||||
->body("Expected format: ItemCode|SerialNumber<br>Received Format '$state'")
|
||||
->title('Invalid Item Code')
|
||||
->body("Item code '$iCode' should contain minimum 6 digits!")
|
||||
->danger()
|
||||
->send();
|
||||
$set('item_code', null);
|
||||
return;
|
||||
}
|
||||
else{
|
||||
$iCode = $parts[0];
|
||||
if (strlen($parts[0]) > 6) {
|
||||
|
||||
Notification::make()
|
||||
->title('Invalid Item Code')
|
||||
->body("Item code '$iCode' should contain minimum 6 digits!")
|
||||
->danger()
|
||||
->send();
|
||||
$set('item_code', null);
|
||||
return;
|
||||
}
|
||||
elseif(!preg_match('/^[a-zA-Z0-9]+$/', $iCode)){
|
||||
Notification::make()
|
||||
->title('Invalid Item Code')
|
||||
->body("Item code '$iCode' should contain alpha numeric values!")
|
||||
->danger()
|
||||
->send();
|
||||
$set('item_code', null);
|
||||
return;
|
||||
}
|
||||
return;
|
||||
} elseif (! preg_match('/^[a-zA-Z0-9]+$/', $iCode)) {
|
||||
Notification::make()
|
||||
->title('Invalid Item Code')
|
||||
->body("Item code '$iCode' should contain alpha numeric values!")
|
||||
->danger()
|
||||
->send();
|
||||
$set('item_code', null);
|
||||
|
||||
return;
|
||||
} else {
|
||||
$set('item_code', trim($parts[0]));
|
||||
$set('serial_number', isset($parts[1]) ? trim($parts[1]) : null);
|
||||
// $set('test_status', 'P');
|
||||
$livewire->dispatch('submit-leak-test-form');
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
->extraAttributes(fn ($get) => [
|
||||
'class' => $get('lsrCodeError') ? 'border-red-500' : '',
|
||||
])
|
||||
@@ -212,7 +188,7 @@ class LeakTestReadingResource extends Resource
|
||||
// $itemCode = $get('item_code');
|
||||
// $serialNumber = $get('serial_number');
|
||||
|
||||
if (! $plantId) { //|| ! $itemCode || ! $serialNumber
|
||||
if (! $plantId) { // || ! $itemCode || ! $serialNumber
|
||||
$set('test_status', null);
|
||||
|
||||
return [];
|
||||
|
||||
Reference in New Issue
Block a user