Javascript - Custom Format and Keystroke Script

Explorer ,
Oct 12, 2019 Oct 12, 2019

Copy link to clipboard

Copied

Hello,

 

I have a field with a custom keystroke:

 

 

if( event.willCommit )
{
   if(event.value == "")
     //if nothing is chosen in box1 then box2 will be cleared
     this.getField("Text412").clearItems();
   else
    SetFieldValues(event.value);
}

 

 

I would also like this same field to be formatted with two places after the decimal. I am assuming I would need to add code to the Custome format Format script to accomplish that but I don't know how or what scritp to write. Since I don't know how to write javascript I just search and try to adapt what I find. I found this talking about a custome format script:Archived Forum Answer (2 places after decimal)

So I thought I just needed to add this line

Number(event.value).toFixed(2);

to the custom format script but it doesn't work. Is it because I need to add more to the script? Or is my approach completely wrong anyway? Any guidance would be appreciated!

 

Thanks!

 

Ariel

TOPICS
Acrobat SDK and JavaScript, How to, PDF forms, Windows

Views

2.0K

Likes

Translate

Translate

Report

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

correct answers 1 Correct Answer

Adobe Community Professional , Oct 13, 2019 Oct 13, 2019
Hi, In the link that you provided there is another link that suggests workarounds and additional options http://khkonsulting.com/2015/09/apply-standard-pdf-form-field-formattingkeystrokevalidation-events-to-fields-via-javascript/ If you read thorugh it there is a part in which the author suggests moving your script as custom calculation script to actually retain the original value of the field amd then apply the numeric formatting by using the built in formatting that is offered in the Format ta...

Likes

Translate

Translate
Adobe Community Professional ,
Oct 13, 2019 Oct 13, 2019

Copy link to clipboard

Copied

Hi,

 

In the link that you provided there is another link that suggests workarounds and additional options

 

http://khkonsulting.com/2015/09/apply-standard-pdf-form-field-formattingkeystrokevalidation-events-t...

 

If you read thorugh it there is a part in which the author suggests moving your script as custom calculation script to actually retain the original value of the field amd then apply the numeric formatting by using the built in formatting that is offered in the Format tab for that field.

 

That is actually the easiest way to accomplish this and there is no need for keystroke .

 

Likes

Translate

Translate

Report

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
Explorer ,
Oct 18, 2019 Oct 18, 2019

Copy link to clipboard

Copied

Thank you, I did just that. I moved the script somewhere else, and used the built-in numeric formatting.

 

Thanks again!

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Oct 19, 2019 Oct 19, 2019

Copy link to clipboard

Copied

LATEST

You're welcome I'm glad it helped.

Likes

Translate

Translate

Report

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