Enhance item description field to auto-populate based on selected item ID

This commit is contained in:
dhanabalan
2025-08-25 12:17:49 +05:30
parent 3a009543ea
commit 1cee8dc71d

View File

@@ -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,10 +154,24 @@ 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()
->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),