This topic is locked
[SOLVED]

Currency Formatting Issue in Add and Edit Pages

2/3/2024 1:37:35 PM
PHPRunner General questions
S
Salvo author

Hello everyone,

I am encountering an issue with formatting a field as currency in the add and edit pages of my PHPRunner project. I want the field to be displayed in the Euro currency format, with two decimal places, using a comma (,) as the decimal separator and a period (.) as the thousand separator. While in the list page the formatting is applied correctly, in the add and edit pages I cannot achieve the same result.

I tried using the PHP number_format() function in the "Before Display" event, but it seems that this approach has no effect on the input fields in the add and edit pages. Here is an example of the code I used:

$data["myField"] = number_format($data["myField"], 2, ',', '.');

I am also open to using JavaScript for client-side formatting, but I would prefer a solution that can be implemented directly through PHPRunner's features, if possible.

Could you kindly provide me with guidance on how to solve this problem? Is there a recommended approach to applying currency formatting in the add and edit pages that I might have missed?

Thank you in advance for the help and suggestions you can provide.

Salvo (from Italy)

fhumanes 2/3/2024

Hello,

I think this article on my website solves your problem.

https://fhumanes.com/blog/guias-desarrollo/guia-58-edicion-de-importes-con-simbolos-de-puntuacion-y-moneda/

Greetings,
fernando

S
Salvo author 2/5/2024

Hi
unfortunately it doesn't work for me.
I tried to strictly follow your instructions as follows:
I downloaded in the path
plugins/jquerymaskmoney/ the Jquery-maskMoney plugin

In the Before Display event I inserted
$html = <<<EOT
<script src="/plugins/jquerymaskmoney/dist/jquery.maskMoney.min.js" type="text/javascript"></script>
EOT;
echo $html;

and in the Javascript Onload event I inserted the following lines
$('input[id^="costonetto"]').maskMoney({thousands:'.', decimal:',', allowZero:true, suffix:' €', precision: 2});
$('input[id^="pricenet"]').maskMoney({thousands:'.', decimal:',', allowZero:true, suffix:' €', affixesStay: true});
$('input[id^="listino2"]').maskMoney({prefix:'R$ ', allowNegative: true, thousands:'.', decimal:',', affixesStay: true});
$('input[id^="listino3"]').maskMoney({prefix:'R$ ', allowNegative: true, thousands:'.', decimal:',', affixesStay: true});

this.on('beforeSave', function(formObj, fieldControlsArr, pageObj){
$('input[id^="costonetto"]').val($('input[id^="costonetto"]').maskMoney('unmasked')[0]);
$('input[id^="pricenet"]').val($('input[id^="pricenet"]').maskMoney('unmasked')[0]);
$('input[id^="listino2"]').val($('input[id^="listino2"]').maskMoney('unmasked')[0]);
$('input[id^="listino3"]').val($('input[id^="listino3"]').maskMoney('unmasked')[0]);
});

In the code of the page I inserted, in the <head> section
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" type="text/javascript"></script>
<script src="jquery.maskMoney.js" type="text/javascript"></script>

What am I doing wrong? What am I leaving out? And where?
Thanks if you can help me.