Enhance production order validation to require numeric values with 7 to 14 digits across multiple resources
This commit is contained in:
@@ -319,8 +319,10 @@ class ProductionQuantityResource extends Resource
|
||||
->label('Production Order')
|
||||
->reactive()
|
||||
->required()
|
||||
->minLength(7)
|
||||
->maxLength(14)
|
||||
->columnSpan(2)
|
||||
// ->rules(['regex:/^[1-9][0-9]{6,}$/'])
|
||||
//->rules(['regex:/^[1-9][0-9]{6,}$/'])
|
||||
// ->disabled(function ($get) {
|
||||
// return $get('item_code');
|
||||
// })
|
||||
@@ -332,15 +334,35 @@ class ProductionQuantityResource extends Resource
|
||||
return $latestProduction ? $latestProduction->production_order : null;
|
||||
})
|
||||
->afterStateUpdated(function ($state, callable $get, callable $set): void {
|
||||
$set('item_code', null);
|
||||
$set('item_id', null);
|
||||
// $set('item_description', null);
|
||||
$set('serial_number', null);
|
||||
$set('validationError', null);
|
||||
return;
|
||||
// if (empty($state)) {
|
||||
// }
|
||||
}),
|
||||
if(!is_numeric($get('production_order')) || !preg_match('/^[1-9][0-9]{6,13}$/', $get('production_order')))
|
||||
{
|
||||
$set('item_code', null);
|
||||
$set('item_id', null);
|
||||
$set('serial_number', null);
|
||||
$set('production_order', null);
|
||||
$set('prodOrdError', "Must be a numeric value with 7 to 14 digits.");
|
||||
$set('validationError', null);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
$set('item_code', null);
|
||||
$set('item_id', null);
|
||||
// $set('item_description', null);
|
||||
$set('serial_number', null);
|
||||
$set('production_order', $state);
|
||||
$set('prodOrdError', null);
|
||||
$set('validationError', null);
|
||||
return;
|
||||
// if (empty($state)) {
|
||||
// }
|
||||
}
|
||||
})
|
||||
->extraAttributes(fn ($get) => [
|
||||
'class' => $get('prodOrdError') ? 'border-red-500' : '',
|
||||
])
|
||||
->hint(fn ($get) => $get('prodOrdError') ? $get('prodOrdError') : null)
|
||||
->hintColor('danger'),
|
||||
Forms\Components\TextInput::make('item_code')
|
||||
->label('Item Code')
|
||||
// ->required()
|
||||
|
||||
Reference in New Issue
Block a user