How to format dependable, readonly(calculated) fields?
I have a form with 3 TextInput fields:
* amount (user enters value here)
* price (comes from db)
* sum (calculated field/value)
I can use Mask for
amount
field but how can i format read-only fields price
and sum
?4 Replies
$this->calculate i am unsure what you are doing in this with the getters and setters. But you would tend to set it. You can add ->disabled() I do believe to make them readonly.
Hi, do you mind to share the tricks how you to populate the sum
Looks like it's done with $this->Calculate and passing the settings and getters so will be setting the sum in the calculate formation. Only updates on changing the amount.
public function calculate(callable $set, callable $get) {
$amount = floatval($get('amount'));
$price = floatval($get('price'));
$sum = $price * $amount;
$set('sum', $this->formatNumber($sum));
}