Refactor work group visibility logic in LineResource form
This commit is contained in:
@@ -20,6 +20,7 @@ use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Filament\Forms\Components\Section;
|
||||
use Filament\Forms\Set;
|
||||
use Filament\Tables\Actions\ExportAction;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Validation\Rules\Unique;
|
||||
@@ -191,30 +192,49 @@ class LineResource extends Resource
|
||||
->maxValue(10)
|
||||
->placeholder('Scan the valid No Of Operatrion')
|
||||
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
|
||||
$partValidationColumns = [
|
||||
'work_group1_id', 'work_group2_id', 'work_group3_id', 'work_group4_id',
|
||||
'work_group5_id', 'work_group6_id', 'work_group7_id', 'work_group8_id',
|
||||
'work_group9_id', 'work_group10_id',
|
||||
];
|
||||
$partValidationColumns = [
|
||||
'work_group1_id', 'work_group2_id', 'work_group3_id', 'work_group4_id', 'work_group5_id',
|
||||
'work_group6_id', 'work_group7_id', 'work_group8_id', 'work_group9_id', 'work_group10_id',
|
||||
];
|
||||
|
||||
foreach ($partValidationColumns as $column) {
|
||||
$set($column . '_visible', false);
|
||||
$set($column, null);
|
||||
}
|
||||
|
||||
if (is_numeric($state) && $state > 0) {
|
||||
for ($i = 1; $i <= (int) $state; $i++) {
|
||||
$set("work_group{$i}_id_visible", true);
|
||||
foreach ($partValidationColumns as $column) {
|
||||
$set($column . '_visible', false);
|
||||
$set($column, null);
|
||||
}
|
||||
}
|
||||
})
|
||||
->afterStateHydrated(function (callable $set, $state) {
|
||||
for ($i = 1; $i <= 10; $i++) {
|
||||
$set("work_group{$i}_id_visible", $state >= $i);
|
||||
}
|
||||
}),
|
||||
|
||||
$partValidDispColumns = [
|
||||
'work_group1_actual_id', 'work_group2_actual_id', 'work_group3_actual_id', 'work_group4_actual_id', 'work_group5_actual_id',
|
||||
'work_group6_actual_id', 'work_group7_actual_id', 'work_group8_actual_id', 'work_group9_actual_id', 'work_group10_actual_id'
|
||||
];
|
||||
|
||||
foreach ($partValidDispColumns as $column) {
|
||||
$set($column, null);
|
||||
}
|
||||
|
||||
if (is_numeric($state) && $state > 0) {
|
||||
for ($i = 1; $i <= (int) $state; $i++) {
|
||||
$set("work_group{$i}_id_visible", true);
|
||||
}
|
||||
}
|
||||
})
|
||||
->afterStateHydrated(function (callable $set, $state) {
|
||||
for ($i = 1; $i <= 10; $i++) {
|
||||
$set("work_group{$i}_id_visible", $state >= $i);
|
||||
}
|
||||
}),
|
||||
|
||||
Forms\Components\Hidden::make('work_group1_id'),
|
||||
// ->afterStateHydrated(function ($component, $state, Get $get, Set $set) {
|
||||
// if ($get('id')) {
|
||||
// $workGroupId = Line::where('id', $get('id'))->first()?->work_group1_id;
|
||||
// if ($workGroupId) {
|
||||
// $set('work_group1_id', $workGroupId);
|
||||
// } else {
|
||||
// $set('work_group1_id', null);
|
||||
// }
|
||||
// }
|
||||
// }),
|
||||
//->required(fn (callable $get) => $get('no_of_operation') >= 1),
|
||||
|
||||
Forms\Components\TextInput::make('work_group1_actual_id')
|
||||
->label('Work Group Center 1')
|
||||
|
||||
Reference in New Issue
Block a user