Enhance CharacteristicApproverMasterResource form with improved validation and field updates
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
This commit is contained in:
@@ -65,41 +65,63 @@ class CharacteristicApproverMasterResource extends Resource
|
|||||||
->afterStateUpdated(function ($state, callable $set) {
|
->afterStateUpdated(function ($state, callable $set) {
|
||||||
$set('updated_by', Filament::auth()->user()?->name);
|
$set('updated_by', Filament::auth()->user()?->name);
|
||||||
}),
|
}),
|
||||||
Forms\Components\TextInput::make('characteristic_field')
|
|
||||||
->label('Master Characteristic Field')
|
|
||||||
->columnSpan(2)
|
|
||||||
->required()
|
|
||||||
->default('NIL')
|
|
||||||
->afterStateUpdated(function ($state, callable $set) {
|
|
||||||
$set('updated_by', Filament::auth()->user()?->name);
|
|
||||||
}),
|
|
||||||
Forms\Components\TextInput::make('machine_name')
|
Forms\Components\TextInput::make('machine_name')
|
||||||
->label('Machine')
|
->label('Machine')
|
||||||
->columnSpan(2)
|
->columnSpan(2)
|
||||||
|
->reactive()
|
||||||
->required()
|
->required()
|
||||||
|
->minLength(5)
|
||||||
->default(function () {
|
->default(function () {
|
||||||
return optional(CharacteristicApproverMaster::latest()->first())->machine_name ?? '';
|
return optional(CharacteristicApproverMaster::latest()->first())->machine_name ?? '';
|
||||||
})
|
})
|
||||||
->afterStateUpdated(function ($state, callable $set) {
|
->afterStateUpdated(function ($state, callable $set) {
|
||||||
$set('updated_by', Filament::auth()->user()?->name);
|
$set('updated_by', Filament::auth()->user()?->name);
|
||||||
}),
|
}),
|
||||||
|
Forms\Components\TextInput::make('characteristic_field')
|
||||||
|
->label('Master Characteristic Field')
|
||||||
|
->columnSpan(2)
|
||||||
|
->reactive()
|
||||||
|
->required()
|
||||||
|
->minLength(1)
|
||||||
|
->default('NIL')
|
||||||
|
->afterStateUpdated(function ($state, callable $set) {
|
||||||
|
if (strtolower($state) == 'nil' || $state == '' || $state == null) {
|
||||||
|
$set('characteristic_field', 'NIL');
|
||||||
|
}
|
||||||
|
$set('updated_by', Filament::auth()->user()?->name);
|
||||||
|
}),
|
||||||
Section::make('Approver - 1')
|
Section::make('Approver - 1')
|
||||||
// ->description('Prevent abuse by limiting the number of requests per period')
|
// ->description('Prevent abuse by limiting the number of requests per period')
|
||||||
->columnSpan(['default' => 2, 'sm' => 4])
|
->columnSpan(['default' => 2, 'sm' => 4])
|
||||||
->schema([
|
->schema([
|
||||||
Forms\Components\TextInput::make('name1')
|
Forms\Components\TextInput::make('name1')
|
||||||
->label('Name')
|
->label('Name')
|
||||||
|
->reactive()
|
||||||
|
->required()
|
||||||
->afterStateUpdated(function ($state, callable $set) {
|
->afterStateUpdated(function ($state, callable $set) {
|
||||||
$set('updated_by', Filament::auth()->user()?->name);
|
$set('updated_by', Filament::auth()->user()?->name);
|
||||||
}),
|
}),
|
||||||
Forms\Components\TextInput::make('mail1')
|
Forms\Components\TextInput::make('mail1')
|
||||||
->label('Mail')
|
->label('E-Mail')
|
||||||
->columnSpan(['default' => 1, 'sm' => 2])
|
->columnSpan(['default' => 1, 'sm' => 2])
|
||||||
|
->reactive()
|
||||||
|
->required()
|
||||||
|
->email()
|
||||||
->afterStateUpdated(function ($state, callable $set) {
|
->afterStateUpdated(function ($state, callable $set) {
|
||||||
$set('updated_by', Filament::auth()->user()?->name);
|
$set('updated_by', Filament::auth()->user()?->name);
|
||||||
}),
|
}),
|
||||||
Forms\Components\TextInput::make('duration1')
|
Forms\Components\TextInput::make('duration1')
|
||||||
->label('Duration (HH.MM)')
|
->label('Duration (HH.MM)')
|
||||||
|
->reactive()
|
||||||
|
->required()
|
||||||
|
->minLength(4)
|
||||||
|
->maxLength(5)
|
||||||
|
->regex('/^([0-9]|0[0-9]|1[0-9]|2[0-3])\.(0[0-9]|[1-5][0-9])$/')
|
||||||
|
->validationMessages([
|
||||||
|
// 'regex' => 'Duration must be 4 digits in HH.MM format (e.g., 12.30, 23.59). Hours: 00-23, Minutes: 00-59.',
|
||||||
|
'regex' => 'Duration must be HH.MM format (example: 00.00 - 23.59)',
|
||||||
|
// 'length' => 'Duration must be exactly 5 characters',
|
||||||
|
])
|
||||||
->afterStateUpdated(function ($state, callable $set) {
|
->afterStateUpdated(function ($state, callable $set) {
|
||||||
$set('updated_by', Filament::auth()->user()?->name);
|
$set('updated_by', Filament::auth()->user()?->name);
|
||||||
}),
|
}),
|
||||||
@@ -111,17 +133,26 @@ class CharacteristicApproverMasterResource extends Resource
|
|||||||
->schema([
|
->schema([
|
||||||
Forms\Components\TextInput::make('name2')
|
Forms\Components\TextInput::make('name2')
|
||||||
->label('Name')
|
->label('Name')
|
||||||
|
->reactive()
|
||||||
->afterStateUpdated(function ($state, callable $set) {
|
->afterStateUpdated(function ($state, callable $set) {
|
||||||
$set('updated_by', Filament::auth()->user()?->name);
|
$set('updated_by', Filament::auth()->user()?->name);
|
||||||
}),
|
}),
|
||||||
Forms\Components\TextInput::make('mail2')
|
Forms\Components\TextInput::make('mail2')
|
||||||
->label('Mail')
|
->label('E-Mail')
|
||||||
->columnSpan(['default' => 1, 'sm' => 2])
|
->columnSpan(['default' => 1, 'sm' => 2])
|
||||||
|
->reactive()
|
||||||
|
->email()
|
||||||
->afterStateUpdated(function ($state, callable $set) {
|
->afterStateUpdated(function ($state, callable $set) {
|
||||||
$set('updated_by', Filament::auth()->user()?->name);
|
$set('updated_by', Filament::auth()->user()?->name);
|
||||||
}),
|
}),
|
||||||
Forms\Components\TextInput::make('duration2')
|
Forms\Components\TextInput::make('duration2')
|
||||||
->label('Duration (HH.MM)')
|
->label('Duration (HH.MM)')
|
||||||
|
->reactive()
|
||||||
|
->length(4)
|
||||||
|
->regex('/^([0-9]|0[0-9]|1[0-9]|2[0-3])\.(0[0-9]|[1-5][0-9])$/')
|
||||||
|
->validationMessages([
|
||||||
|
'regex' => 'Duration must be HH.MM format (example: 00.00 - 23.59)',
|
||||||
|
])
|
||||||
->afterStateUpdated(function ($state, callable $set) {
|
->afterStateUpdated(function ($state, callable $set) {
|
||||||
$set('updated_by', Filament::auth()->user()?->name);
|
$set('updated_by', Filament::auth()->user()?->name);
|
||||||
}),
|
}),
|
||||||
@@ -133,17 +164,26 @@ class CharacteristicApproverMasterResource extends Resource
|
|||||||
->schema([
|
->schema([
|
||||||
Forms\Components\TextInput::make('name3')
|
Forms\Components\TextInput::make('name3')
|
||||||
->label('Name')
|
->label('Name')
|
||||||
|
->reactive()
|
||||||
->afterStateUpdated(function ($state, callable $set) {
|
->afterStateUpdated(function ($state, callable $set) {
|
||||||
$set('updated_by', Filament::auth()->user()?->name);
|
$set('updated_by', Filament::auth()->user()?->name);
|
||||||
}),
|
}),
|
||||||
Forms\Components\TextInput::make('mail3')
|
Forms\Components\TextInput::make('mail3')
|
||||||
->label('Mail')
|
->label('E-Mail')
|
||||||
->columnSpan(['default' => 1, 'sm' => 2])
|
->columnSpan(['default' => 1, 'sm' => 2])
|
||||||
|
->reactive()
|
||||||
|
->email()
|
||||||
->afterStateUpdated(function ($state, callable $set) {
|
->afterStateUpdated(function ($state, callable $set) {
|
||||||
$set('updated_by', Filament::auth()->user()?->name);
|
$set('updated_by', Filament::auth()->user()?->name);
|
||||||
}),
|
}),
|
||||||
Forms\Components\TextInput::make('duration3')
|
Forms\Components\TextInput::make('duration3')
|
||||||
->label('Duration (HH.MM)')
|
->label('Duration (HH.MM)')
|
||||||
|
->reactive()
|
||||||
|
->length(4)
|
||||||
|
->regex('/^([0-9]|0[0-9]|1[0-9]|2[0-3])\.(0[0-9]|[1-5][0-9])$/')
|
||||||
|
->validationMessages([
|
||||||
|
'regex' => 'Duration must be HH.MM format (example: 00.00 - 23.59)',
|
||||||
|
])
|
||||||
->afterStateUpdated(function ($state, callable $set) {
|
->afterStateUpdated(function ($state, callable $set) {
|
||||||
$set('updated_by', Filament::auth()->user()?->name);
|
$set('updated_by', Filament::auth()->user()?->name);
|
||||||
}),
|
}),
|
||||||
@@ -205,7 +245,7 @@ class CharacteristicApproverMasterResource extends Resource
|
|||||||
->searchable()
|
->searchable()
|
||||||
->sortable(),
|
->sortable(),
|
||||||
Tables\Columns\TextColumn::make('mail1')
|
Tables\Columns\TextColumn::make('mail1')
|
||||||
->label('Mail 1')
|
->label('E-Mail 1')
|
||||||
->alignCenter()
|
->alignCenter()
|
||||||
->searchable()
|
->searchable()
|
||||||
->sortable(),
|
->sortable(),
|
||||||
@@ -219,7 +259,7 @@ class CharacteristicApproverMasterResource extends Resource
|
|||||||
->searchable()
|
->searchable()
|
||||||
->sortable(),
|
->sortable(),
|
||||||
Tables\Columns\TextColumn::make('mail2')
|
Tables\Columns\TextColumn::make('mail2')
|
||||||
->label('Mail 2')
|
->label('E-Mail 2')
|
||||||
->alignCenter()
|
->alignCenter()
|
||||||
->searchable()
|
->searchable()
|
||||||
->sortable(),
|
->sortable(),
|
||||||
@@ -233,7 +273,7 @@ class CharacteristicApproverMasterResource extends Resource
|
|||||||
->searchable()
|
->searchable()
|
||||||
->sortable(),
|
->sortable(),
|
||||||
Tables\Columns\TextColumn::make('mail3')
|
Tables\Columns\TextColumn::make('mail3')
|
||||||
->label('Mail 3')
|
->label('E-Mail 3')
|
||||||
->alignCenter()
|
->alignCenter()
|
||||||
->searchable()
|
->searchable()
|
||||||
->sortable(),
|
->sortable(),
|
||||||
|
|||||||
Reference in New Issue
Block a user