Added id column to load default plant with its validation functionality

This commit is contained in:
dhanabalan
2025-05-31 16:10:56 +05:30
parent 376d0800dd
commit 044d27336d

View File

@@ -36,29 +36,30 @@ class MotorTestingMasterResource extends Resource
return $form
->schema([
Forms\Components\Select::make('plant_id')
->label('Plant')
->relationship('plant', 'name')
->required()
->reactive()
->default(function () {
return optional(Item::latest()->first())->plant_id;
})
->disabled(fn (Get $get) => !empty($get('id')))
->afterStateUpdated(function ($state, callable $set, callable $get) {
$plantId = $get('plant_id');
if (!$plantId) {
$set('mTmError', 'Please select a plant first.');
return;
}
else
{
$set('mTmError', null);
}
})
->extraAttributes(fn ($get) => [
'class' => $get('mTmError') ? 'border-red-500' : '',
])
->hint(fn ($get) => $get('mTmError') ? $get('mTmError') : null)
->hintColor('danger'),
->required()
->reactive()
->default(function () {
return optional(MotorTestingMaster::latest()->first())->plant_id;
})
->disabled(fn (Get $get) => !empty($get('id')))
->afterStateUpdated(function ($state, callable $set, callable $get) {
$plantId = $get('plant_id');
if (!$plantId) {
$set('mTmError', 'Please select a plant first.');
return;
}
else
{
$set('mTmError', null);
}
})
->extraAttributes(fn ($get) => [
'class' => $get('mTmError') ? 'border-red-500' : '',
])
->hint(fn ($get) => $get('mTmError') ? $get('mTmError') : null)
->hintColor('danger'),
Forms\Components\Select::make('item_id')
->label('Item')
->options(function (callable $get) {
@@ -226,6 +227,9 @@ class MotorTestingMasterResource extends Resource
Forms\Components\Hidden::make('updated_by')
->default(fn () => Filament::auth()->user()?->name)
->required(),
Forms\Components\TextInput::make('id')
->hidden()
->readOnly(),
]);
}