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