Money formatting a live field
Hi there, I am trying to format a live field as money
The field that is being updated is defined as following:
TextInput::make('price')->label(new HtmlString('Jedinična cijena'))
->readOnly()
->suffix('€')
->default(0)
->currencyMask(thousandSeparator: '.',decimalSeparator: ',',precision: 2)
->extraInputAttributes(['style' => 'text-align:right;']),
Field gets updated by using the following:
->afterStateUpdated(function (Get $get, Set $set, ?string $old, ?string $state) {
$type = $get('type');
if($type == null || $get('product_id') == null) { return $set('price', 0); }
if ($type == 0) {
$set('price', Auth::user()->team()->products()->where('id', $get('product_id'))->first()->price);
return $set('itemTotal', $get('price') * $get('quantity'));
}
$set('price', Auth::user()->team()->services()->where('id', $get('product_id'))->first()->price);
return $set('itemTotal', $get('price') * $get('quantity'));
}),
I tried using RawJS as mentioned in the docs, but the changes are not being reflected. Is there a way to force it to use two decimal places? Field is not marked as numeric because I don't want those arrows to be visible to the user, because the field is read onlySolution:Jump to solution
I use following helper from laravel
https://laravel.com/docs/10.x/helpers#method-number-currency
```php...
2 Replies
Solution
Thanks, saved my day. Totally forgot about that