Repeater immediately change field after another field changes

i needed whenever quantity is changed to automatically set the value to remaining quantity as i type.
Forms\Components\Repeater::make('products')->columnSpan('full')
                                    ->schema([
                                        Forms\Components\TextInput::make('product_name')->required()->columnSpan(2),
                                        Forms\Components\TextInput::make('quantity')->required()->numeric()
                                            ->afterStateUpdated(function ($state, callable $set ){          $set('remaining_qty', $state);
                                            }),
                                        Forms\Components\TextInput::make('total_kg')->required()->numeric(),
                                        Forms\Components\Placeholder::make('remaining_qty')
                                            ->content(function (callable $get){
                                                return $get('remaining_qty');
                                            }),
                                        Forms\Components\TextInput::make('total_cbm')->required()->numeric(),
                                        Forms\Components\Select::make('uom')
                                            ->options([
                                                'cartoon' => 'Cartoon',
                                                'box' => 'Box',
                                                'bundle' => 'Bundle',
                                            ])
                                            ->required(),

                                    ])
                                    ->collapsible()->columns(7),
                                // ...
                            ]),
Screenshot_2023-08-09_004709.png
Solution
So you will need to make quanity reactive.

Then use the $record, get the $record for the product and it's quanity, and - this quanity from the records quanity.
Was this page helpful?