Refresh repeater values when value outside repeater changes
I have this TVA field and when its udpated I want the values inside the repeater to refresh, change etc...
```
Forms\Components\TextInput::make('tva')->live()->label('TVA')->afterStateUpdated(function($get, $set){
foreach ($get('products') as $key => $data){
$set("products/$key/qty", $data['qty']);
}
})->numeric()->default(0),
Repeater::make('products')->label('Produse')
->columnSpan('2')
->live()
->schema([
Forms\Components\Select::make('product')->label('Produs')->searchable()->relationship('products', 'name')->required()->createOptionForm([
TextInput::make('name'),
TextInput::make('unit'),
TextInput::make('price_per_unit'),
])->createOptionUsing(function ($data) {
return auth()->user()->products()->create($data);
})->columnSpan(2)->live()->afterStateUpdated(function ($state, $set) {
$produs = Product::find($state);
$set('unit', $produs->unit);
$set('ppu', $produs->price_per_unit);
}),
TextInput::make('qty')->label('Cantitate')->live()->afterStateUpdated(function ($state, $set, $get) {
$produs = Product::find($get('product'));
$curr = $get('../../moneda');
$tva = $get('../../tva');
if (!$produs) return;
$set('unit', $produs->unit);
$set('ppu', $produs->price_per_unit);
$total_no_vat = (int)$state * $produs->price_per_unit;
$total_with_vat = $tva ? Number::currency($total_no_vat * ((double)("1.".$tva)), $curr) : Number::currency($total_no_vat, $curr);
$total_vat = $tva ? Number::currency($total_no_vat * ((double)("1.".$tva)), $curr) : Number::currency(0, $curr);
$set('total_price_no_vat', Number::currency($total_no_vat, $curr));
$set('total_price_vat',$total_with_vat);
$set('total_vat',$total_vat);
})->required()->columnSpan(1),
2 Replies
thank you sir, fixed it by doing this:
in my afterStateUpdated on the prop that changes