From 1cee8dc71d1375c44a35eeec316b0520358c8ed4 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Mon, 25 Aug 2025 12:17:49 +0530 Subject: [PATCH] Enhance item description field to auto-populate based on selected item ID --- .../Resources/StickerMasterResource.php | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/app/Filament/Resources/StickerMasterResource.php b/app/Filament/Resources/StickerMasterResource.php index 23ccffc..1adad80 100644 --- a/app/Filament/Resources/StickerMasterResource.php +++ b/app/Filament/Resources/StickerMasterResource.php @@ -18,6 +18,7 @@ use Filament\Tables\Table; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\SoftDeletingScope; use Filament\Forms\Get; +use Filament\Forms\Set; use Filament\Tables\Actions\ExportAction; use Filament\Tables\Actions\ImportAction; // use Illuminate\Validation\Rule; @@ -153,12 +154,26 @@ class StickerMasterResource extends Resource ->hint(fn ($get) => $get('item_error') ? $get('item_error') : null) ->hintColor('danger'), - Forms\Components\TextInput::make('item_description') - ->label('Description') - ->required() - ->reactive() - ->readOnly(true), + ->label('Description') + ->required() + ->afterStateHydrated(function ($component, $state, Get $get, Set $set) { + if ($get('id')) { + $itemId = StickerMaster::where('id', $get('id'))->first()?->item_id; + if ($itemId) { + $item = \App\Models\Item::where('id', $itemId)->first()?->description; + if ($item) { + $set('item_description', $item); + } else { + $set('item_description', null); + } + } else { + $set('item_description', null); + } + } + }) + ->reactive() + ->readOnly(true), Forms\Components\TextInput::make('part_validation1') ->nullable(),