Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Custom currency format replace zero

Participant ,
Oct 22, 2021 Oct 22, 2021

Hello, i would like to know if it is possible to change the number format of a field.

Currently i am using the default number format with thousand seperator and 2 decimals and the "€" symbol behind with a space e.g. "12.500,00 €".

In this format an empty field would be totally empty, but i would like to show up "-     €" when the field is empty. Is that possible with a custom format?

 

Thank you very much in advance.

TOPICS
Create PDFs , Edit and convert PDFs , How to , JavaScript , PDF forms
1.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
Community Expert ,
Oct 23, 2021 Oct 23, 2021

As 'Custom format script' use this:

if(event.value == "")
event.value = "- €";
else
event.value = util.printf("€ %,2.2f",event.value);

 

If you wish to allow only numbers to be entered in field, use this as 'Custom keystroke script':

event.rc = /^\d*$/.test(event.change);

 

 

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 23, 2021 Oct 23, 2021

As 'Custom format script' use this:

if(event.value == "")
event.value = "- €";
else
event.value = util.printf("€ %,2.2f",event.value);

 

If you wish to allow only numbers to be entered in field, use this as 'Custom keystroke script':

event.rc = /^\d*$/.test(event.change);

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 23, 2021 Oct 23, 2021

Thank you very much, that works perfectly.

I changed the output at else a little bit so that the € is comming behind the number and it works.

event.value = util.printf("%,2.2f €",event.value);

Now the only problem is, that i have a Button to reset all fields.

This Button runs the code

if(4==app.alert("The form will be resetted.\n\nAll data will be removed! Continue?",1,2)) {
  this.resetForm(["Field1", "Field2", "Field2"]);
  this.getField("top").setFocus();
}

When running this code, the input with the format script outputs the following:

1,#R €

 This field should be resetted to the default value which is currently a number (40).

Do i have to change anything?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 23, 2021 Oct 23, 2021
LATEST

EDIT: was my fail, had a calculation script in the field which causes the error

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 23, 2021 Oct 23, 2021

Keep the format settings and add this script as a Validation script in your field:

 

if (event.value == 0) {event.value = "- €"};


Acrobate du PDF, InDesigner et Photoshopographe
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines