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),
// ...
]),
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),
// ...
]),
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....
Jump to solution
3 Replies
Solution
toeknee
toeknee12mo ago
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.
Adnan Yalahow
Adnan Yalahow12mo ago
It worked. Thank you
toeknee
toeknee12mo ago
Welcome