Ahmed Ogua
TLCTuto's Laravel Corner
•Created by Ahmed Ogua on 5/6/2024 in #💡filament
Populate repeater using a select field outside of repeater rather than using the repeater add button
This is my code.
Hoe do i use this select filed to poupulate my repeater.
Forms\Components\Select::make('scan_code')
->label('')
->getSearchResultsUsing(fn (string $search): array => (new Saleservice())->getproductdetails($search))
->preload()
->placeholder("Scan / Search product by name / code")
->columnSpanFull()
->searchable()
->dehydrated(false)
->required(),
Forms\Components\Repeater::make('saleitem')
->label('')
->relationship()
->columnSpan("full")
->schema([
Forms\Components\TextInput::make('product_id') ->label('Product') ->required(),
Forms\Components\TextInput::make('unit_price') ->type("number") ->disabled() ->dehydrated() ->label('Price') ->required(),
Forms\Components\TextInput::make('qty') ->numeric() ->default(1) ->live() ->dehydrated() ->afterStateUpdated(function (Forms\Get $get,Forms\Set $set, $state){ $tot = $state * $get('unit_price'); $set("total",$tot); }) ->required(),
]) ->columns(4) ->addActionLabel('Add Item') ->cloneable() ->mutateRelationshipDataBeforeCreateUsing(function (array $data): array { $data['external_id'] = auth()->user()->id; return $data; }),
Forms\Components\TextInput::make('product_id') ->label('Product') ->required(),
Forms\Components\TextInput::make('unit_price') ->type("number") ->disabled() ->dehydrated() ->label('Price') ->required(),
Forms\Components\TextInput::make('qty') ->numeric() ->default(1) ->live() ->dehydrated() ->afterStateUpdated(function (Forms\Get $get,Forms\Set $set, $state){ $tot = $state * $get('unit_price'); $set("total",$tot); }) ->required(),
]) ->columns(4) ->addActionLabel('Add Item') ->cloneable() ->mutateRelationshipDataBeforeCreateUsing(function (array $data): array { $data['external_id'] = auth()->user()->id; return $data; }),
1 replies