Enhance item description field to auto-populate based on selected item ID
This commit is contained in:
@@ -18,6 +18,7 @@ use Filament\Tables\Table;
|
|||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||||
use Filament\Forms\Get;
|
use Filament\Forms\Get;
|
||||||
|
use Filament\Forms\Set;
|
||||||
use Filament\Tables\Actions\ExportAction;
|
use Filament\Tables\Actions\ExportAction;
|
||||||
use Filament\Tables\Actions\ImportAction;
|
use Filament\Tables\Actions\ImportAction;
|
||||||
// use Illuminate\Validation\Rule;
|
// use Illuminate\Validation\Rule;
|
||||||
@@ -153,12 +154,26 @@ class StickerMasterResource extends Resource
|
|||||||
->hint(fn ($get) => $get('item_error') ? $get('item_error') : null)
|
->hint(fn ($get) => $get('item_error') ? $get('item_error') : null)
|
||||||
->hintColor('danger'),
|
->hintColor('danger'),
|
||||||
|
|
||||||
|
|
||||||
Forms\Components\TextInput::make('item_description')
|
Forms\Components\TextInput::make('item_description')
|
||||||
->label('Description')
|
->label('Description')
|
||||||
->required()
|
->required()
|
||||||
->reactive()
|
->afterStateHydrated(function ($component, $state, Get $get, Set $set) {
|
||||||
->readOnly(true),
|
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')
|
Forms\Components\TextInput::make('part_validation1')
|
||||||
->nullable(),
|
->nullable(),
|
||||||
|
|||||||
Reference in New Issue
Block a user