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
D Terminal Dev
D Terminal DevOP7mo ago
thank you sir, fixed it by doing this:
Forms\Components\TextInput::make('tva')->default(19)->live()->label('TVA')->suffix('%')->afterStateUpdated(function ($state, $get, $set) {
// dd($get('products'));
// if($state == 0) return;
foreach ($get('products') as $key => $data) {
$vat_val = (double)$state / 100;
if (!$data['product'] && !$data['qty']) continue;


$with_vat = $state == 0 ? 0 : $data['total_price_no_vat'] * (1 + $vat_val);

$vat = $state == 0 ? 0 : $data['total_price_no_vat'] * $vat_val;
$set("products.$key.total_price_vat", round($with_vat, 2));
$set("products.$key.total_vat", round($vat, 2));
}
})->numeric(),
Forms\Components\TextInput::make('tva')->default(19)->live()->label('TVA')->suffix('%')->afterStateUpdated(function ($state, $get, $set) {
// dd($get('products'));
// if($state == 0) return;
foreach ($get('products') as $key => $data) {
$vat_val = (double)$state / 100;
if (!$data['product'] && !$data['qty']) continue;


$with_vat = $state == 0 ? 0 : $data['total_price_no_vat'] * (1 + $vat_val);

$vat = $state == 0 ? 0 : $data['total_price_no_vat'] * $vat_val;
$set("products.$key.total_price_vat", round($with_vat, 2));
$set("products.$key.total_vat", round($vat, 2));
}
})->numeric(),
in my afterStateUpdated on the prop that changes
Want results from more Discord servers?
Add your server