F
Filament11mo ago
Prosp30

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 only
No description
Solution:
I use following helper from laravel https://laravel.com/docs/10.x/helpers#method-number-currency ```php...
Jump to solution
2 Replies
Solution
Tieme
Tieme11mo ago
I use following helper from laravel https://laravel.com/docs/10.x/helpers#method-number-currency
if ($type == 0) {
$set('price', Number::currency(Auth::user()->team()->products()->where('id', $get('product_id'))->first()->price));
return Number::currency($set('itemTotal', $get('price') * $get('quantity')));
}
$set('price', Number::currency(Auth::user()->team()->services()->where('id', $get('product_id'))->first()->price));
return Number::currency($set('itemTotal', $get('price') * $get('quantity')));
if ($type == 0) {
$set('price', Number::currency(Auth::user()->team()->products()->where('id', $get('product_id'))->first()->price));
return Number::currency($set('itemTotal', $get('price') * $get('quantity')));
}
$set('price', Number::currency(Auth::user()->team()->services()->where('id', $get('product_id'))->first()->price));
return Number::currency($set('itemTotal', $get('price') * $get('quantity')));
Prosp30
Prosp30OP11mo ago
Thanks, saved my day. Totally forgot about that

Did you find this page helpful?