FilamentF
Filament2y ago
Emaz

Fields being cleared out due to $set call on other fields

This is a bit hard to explain. I have a repeater with two fields, height and width. The repeater is live as are the 2 TextInputs. Then I have a placeholder which does a bunch of calculations.

Placeholder::make('') ->content(function ($get, $set) { $total = static::newCalcTotal($set, $get); return new HtmlString("<p></p><br><h1><b>TOTAL $ $total</b></h1>"); })

newCalcTotal does a bunch of gets, calculates a total for an estimate and sets a few variables. @Dan Harrin gave me some brilliant guidance on this, doing all the calculations in one place and it's working great. Except for this weird issue.

It does NOT touch the height and width fields. Yet clearly, after the calculation, often times the field that has focus (height or width) gets reset to the previous value after the calculation is complete. I validated this by removing the newCalcTotal method call and the problem goes away. One more debug point, which is weird, if I remove the set calls within newCalcTotal the problem also goes away. The $sets I use are unrelated to height/width:

$set('calculations', $calcString); $set('grandTotal', sprintf("%01.2f", $grand )); $set('glass_total', $glassTotal); $set('hardware_total', $hwTotal); $set('labor_total', $laborTotal); $set('energy_total', $energy); $set('tax_amount', $tax); $set('grand_total', $grand);

I need these sets as they are the result of all the calculations and are stored as part of the record. But if I comment out these $sets, the problem goes away.

I've NO idea how to debug this. It's clearly related to $set although I am NOT setting height or width.
Was this page helpful?