F
Filament2mo ago
tuseto

Repeater add/remove item causes form re-render and js modified values reset to defaults

I have a VANILLA JS calculation in a filament form because I want to calculate without backend requests. I have repeater on the page and when I add/remove item from the repeater it triggers update request which re-renders the form and my js calculated values are gone. Example: I have 3 inputs (x,y,z) one of them (z) is disabled and is calculated via js. x*y=z I want to save all 3 of them into the db. If I change x or y I calculate the rezult and put the value into z. Then when I add/remove repeater x and y stays as I changed them, but z gets the original value. How I can prevent this and keep the js calculated value. Filament v4
4 Replies
Dennis Koch
Dennis Koch2mo ago
Please share some code
tuseto
tusetoOP2mo ago
This is the file that makes the calculations. I just need somehow to prevent the adding and removing repeater item change values in the form because of the re-render
tuseto
tusetoOP2mo ago
Here is the form
tuseto
tusetoOP2mo ago
So lack of knowledge on my side. Basically you should not update input fields directly with vanilla js. You should use this.$wire.set(v,b, false) , otherwise input values are reset maybe because something happen and values are reloaded from alpine instance of the livewire model. Thank you for trying to help @Dennis Koch

Did you find this page helpful?