Emaz
Fields being cleared out due to $set call on other fields
It would be HUGE. I'd feel bad about the amount of effort for you to look at it. I wish somebody would do a tutorial on these more complex scenarios. I bet a lot of us need to figure this out. A service class is a great idea, and doing at save/create/edit is probably key. Thanks!
It's almost amusing. I wasn't daunted by the number of fields. I figured a few gets, a few sets, throw them in the right places with a
afterStateUpdated
and we're golden! Ha, I wish.47 replies
Fields being cleared out due to $set call on other fields
I do have one method for the calculations.
But the idea of a refactor to a service class and calculating at save/create/edit is intriguing. Thanks for the tip about danger of the hidden fields.
Still don't understand though how it's impacting a repeater field. But I know you can't figure that out with small peaks at the code. This is a tough one for sure. I appreciate you going down the rabbit hole with me though.
47 replies
Fields being cleared out due to $set call on other fields
Wouldn't surprise me and I wouldn't be offended. LOL. What I can say is this - there are TONS of fields and calculations and they're all live. It's been fun. But I don't know of another way. Every field impacts the total and so I have all the calcualtions in one place. Just a bunch of gets and the sets I showed. Not sure how else it can be done?
47 replies
Fields being cleared out due to $set call on other fields
They're all just hidden fields at the root level
Hidden::make('glass_total'),
Hidden::make('hardware_total'),
Hidden::make('labor_total'),
Hidden::make('energy_total'),
Hidden::make('grand_total'),
Hidden::make('tax_amount'),
47 replies
Fields being cleared out due to $set call on other fields
Happy to share more code but I know this is asking a lot so I'll try to give the key pieces. Even just giving me things to consider would be helpful.
``php
Section::make('Panels')
->columns(6)
->collapsible()
->schema([
Repeater::make('panels')
->relationship('panels')
->grid(6)
// ->visibleOn('create')
->live()
->reorderable(false)
->cloneable()
->schema([
TextInput::make('width')->required()->numeric()->live(onBlur: true)->columnSpan(1),
TextInput::make('height')->required()->numeric()->live(onBlur: true)->columnSpan(1),
])->columnSpan(6),
]),
Placeholder::make('')
->content(function ($set, $get) {
$total = static::newCalcTotal($set, $get);
return new HtmlString("<p></p><br><h1><b>TOTAL $ $total</b></h1>");
})
public static function newCalcTotal($set, $get)
{
// lots of calculations and ends with:
// AND if these are commented out the issue absolutely goes away
$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);
return $grand;
}
47 replies
Fields being cleared out due to $set call on other fields
Yeah this is a tough one. I'm trying to think how to distill it down. When I made the same repeater elsewhere and kept it simple, no issue. Maybe I'll make a call with a sleep to simulate a latency issue. But I'm not entirely sure that's what's happening. All I can say with certainty is that the field changes after you're done typing. Like frequently. It seems to revert to the prior state.
47 replies
Fields being cleared out due to $set call on other fields
Ugh, I think it's the static part of the call.
$total = static::newCalcTotal($set, $get);
But I'm not sure how else to call it from with the Placeholder. I guess I can try a gigantic closure.
I believe this because when I replace that call with a string, it goes away. But I guess that can still be latency.47 replies
Fields being cleared out due to $set call on other fields
Debounce on the fields seem to be related. With no debounce the problem is very repeatable - a fast typist will often lose the second number when typing a 2-digit width. On the other end of the spectrum if I debounce for 2 secs, the same issue happens after the 2 secs.
47 replies
Setting/getting nested data form wide
I KNEW I was doing it wrong LOL. Thank you Dan. This would make a great tutorial or video series - I wish I had the time to do one. I just suspect others might make the same mistake in doing the calculations. My initial thought was to do it right at the field that changed. That can get real complicated real fast.
13 replies
Setting/getting nested data form wide
Oh good point. I am already using a placeholder. So you mean move all the totaling over there in once place. I guess that simplifies things because now the nesting will be all from one place? So the gets that need "../../" will at least be consistent.
So I DID over complicate by doing the calculations at each field that changes, thus creating the nesting that varies. Better to do it all at the placeholder element.
That's what you're saying, right?
13 replies