Skip to main content
arielreyes001
Inspiring
October 12, 2019
Answered

Javascript - Custom Format and Keystroke Script

  • October 12, 2019
  • 1 reply
  • 7299 views

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

This topic has been closed for replies.
Correct answer ls_rbls

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 tab for that field.

 

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

 

1 reply

ls_rbls
Community Expert
ls_rblsCommunity ExpertCorrect answer
Community Expert
October 14, 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 tab for that field.

 

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

 

arielreyes001
Inspiring
October 19, 2019

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

 

Thanks again!

ls_rbls
Community Expert
Community Expert
October 20, 2019

You're welcome I'm glad it helped.