The sum of dehydrated disabled and field in the repeater was late in realtime, and I got wrong total

Repeater::make('test') ->columns(3) ->defaultItems(3) ->reactive() ->afterStateUpdated(function ($set, $get) { $sumOfPrice1 = collect($get('test'))->pluck('price1')->sum(); $sumOfPrice2 = collect($get('test'))->pluck('price2')->sum(); $set('sum_of_price1', $sumOfPrice1); $set('sum_of_price2', $sumOfPrice2); }) ->schema([ TextInput::make('price1') ->integer() ->reactive() ->afterStateUpdated(fn ($set, $state) => $set('price2', $state)) ->required(), TextInput::make('price2') ->disabled() ->dehydrated(), ]), TextInput::make('sum_of_price1') ->disabled() ->dehydrated(), TextInput::make('sum_of_price2') ->disabled() ->dehydrated(), In above repeater, The sum of price2 is not correct in realtime. Please, How to solve? I want the value of Sum of Price1 field by suming the value from price1 in the repeater, And also, I want the value of Sum of Price2 field by suming the value from price2 in the repeater, Note: the price2 field value was not type, state clone from price1 field
in above ui result price1 was 100 
the sum of price1 fields in the repeater shown in Sum od Price1 was 100 right 

but The value of Price2 field was 100 
and also the sum of price2 should be 100 but got 0. I think It lates in realtime if type a value the second items of price 1. The sum of price2 was 100 shown in Sum of Price2 was appear but still worng the total value.
2 Replies
Myo Zin Kyaw
Myo Zin KyawOP5mo ago
In the picture, The sum of price1 Field in the repeater shown in the TexInput(Sum Of Prcie1) was 100 is right, the price2 field is get a value state from price1 The worng things is the sum of price2 field show it in the TextInput(sum of price2), I think I was late output when I type, If I type second price1 field, the sum of price2 field was set 100, but total sum of price2 field should be first item of price1 field + second item of price2 field. it still late to get total value Please, How to solve???:fi:
Dennis Koch
Dennis Koch5mo ago
Instead of $set()ing a sum, it would be a better approach to use ->formatStateUsing() on the inputs that show the sum and use a callback to calculate it from the repeater data. I could imagine that $set('price2') runs after the repeater callback is fired.
Want results from more Discord servers?
Add your server