Enhance production order validation to require numeric values with 7 to 14 digits across multiple resources
This commit is contained in:
@@ -320,23 +320,44 @@ class ProductionQuantityPage extends Page implements HasForms
|
||||
->hintColor('danger'),
|
||||
|
||||
TextInput::make('production_order')
|
||||
->label('Production Order')
|
||||
->reactive()
|
||||
->required()
|
||||
//->columnSpan(1)
|
||||
->columnSpan(['default' => 1, 'sm' => 1])
|
||||
->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);
|
||||
$this->prodOrder = $state;
|
||||
|
||||
return;
|
||||
// if (empty($state)) {
|
||||
// }
|
||||
}),
|
||||
->label('Production Order')
|
||||
->reactive()
|
||||
->required()
|
||||
->minLength(7)
|
||||
->maxLength(14)
|
||||
//->columnSpan(1)
|
||||
->columnSpan(['default' => 1, 'sm' => 1])
|
||||
->afterStateUpdated(function ($state, callable $get, callable $set): void {
|
||||
if(!is_numeric($get('production_order')) || !preg_match('/^[1-9][0-9]{6,13}$/', $get('production_order')))
|
||||
{
|
||||
$set('productionError', "Must be a numeric value with 7 to 14 digits.");
|
||||
$set('production_order', null);
|
||||
$set('item_code', null);
|
||||
$set('item_id', null);
|
||||
// $set('item_description', null);
|
||||
$set('serial_number', null);
|
||||
$set('validationError', null);
|
||||
$this->prodOrder = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
$set('productionError', null);
|
||||
$set('production_order', $state);
|
||||
$set('item_code', null);
|
||||
$set('item_id', null);
|
||||
// $set('item_description', null);
|
||||
$set('serial_number', null);
|
||||
$set('validationError', null);
|
||||
$this->prodOrder = $state;
|
||||
// if (empty($state)) {
|
||||
// }
|
||||
}
|
||||
})
|
||||
->extraAttributes(fn ($get) => [
|
||||
'class' => $get('productionError') ? 'border-red-500' : '',
|
||||
])
|
||||
->hint(fn ($get) => $get('productionError') ? $get('productionError') : null)
|
||||
->hintColor('danger'),
|
||||
|
||||
// TextInput::make('item_code')
|
||||
// ->label('Item Code')
|
||||
@@ -592,7 +613,7 @@ class ProductionQuantityPage extends Page implements HasForms
|
||||
->send();
|
||||
return;
|
||||
}
|
||||
else if (!preg_match('/^[1-9][0-9]{6,}$/', $this->prodOrder))
|
||||
else if (!preg_match('/^[1-9][0-9]{6,13}$/', $this->prodOrder))
|
||||
{
|
||||
$this->form->fill([
|
||||
'plant_id'=> $this->pId,
|
||||
@@ -611,7 +632,7 @@ class ProductionQuantityPage extends Page implements HasForms
|
||||
|
||||
Notification::make()
|
||||
->title('Invalid Production Order')
|
||||
->body("Must contain at least 7 digits.<br>Must start with a non-zero digit.")
|
||||
->body("Must be a numeric value with 7 to 14 digits.<br>Must start with a non-zero digit.")
|
||||
->danger()
|
||||
->send();
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user