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

this script works but it needs to show only as seen in example

Participant ,
Apr 26, 2019 Apr 26, 2019

Copy link to clipboard

Copied

try67 was nice enough to provide this script (see below). It works great but I noticed it allows me to enter text in the field. Don't want that. The field should only allow a dollar amount to be entered and accepted. Can someone show me how to modify this bit of script to not allow text? Thank you.

script:

if (event.value) { 

    event.value = "$" + util.printf("%,0.2f", event.value) + "/ per foot"; 

}

I've placed the script under Custom Format.

TOPICS
Acrobat SDK and JavaScript , Windows

Views

630

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
LEGEND ,
Apr 26, 2019 Apr 26, 2019

Copy link to clipboard

Copied

You'd need to add a custom Keystroke script. When you say you want to enter a dollar amount, do you want to allow cents as well?

Votes

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
Participant ,
Apr 26, 2019 Apr 26, 2019

Copy link to clipboard

Copied

hi George, yes I want to show the dollars and cents. As it is right now, I can do that. Like this, if I enter 25.58 the field shows $25.58 per foot. But, if I enter some text, the field shows the text and the "per foot". Not what I want to do. It doesn't make sense. I don't know how to modify the script to do as you're saying. Would I just place the script to the Keystroke window? Would modifying this script be too complicated?

Votes

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
LEGEND ,
Apr 27, 2019 Apr 27, 2019

Copy link to clipboard

Copied

No, you'd need to write a second piece of script to control what the user types.

Or modify the first strip to remove everything that isn't one of your legal 11 characters.

Votes

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
Advocate ,
Apr 27, 2019 Apr 27, 2019

Copy link to clipboard

Copied

George and "Test Screen Name" are kind of correct.

If you just want to viszally display something, you don't need a Keystroke event script, and you can do the character filtering in the Format event.

HOWEVER, if you want to do something with the value, you will already have to make sure that only legal characters are entered. Otherwise, you will have garbage input into your further calculations.

A very simplistic approach is to make sure you work with a string, and then use the replace() function with an according Regular Expression.

In the Keystroke Event, you would use this script:

     if (!event.willCommit) {

     event.change = event.change.toString().replace(/[^\d.]/gim, "") ;

     }

This will drop any entered character, except numbers, the minus sign and the period.

Then you can use the already mentioned script in the Format event.

Votes

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
Community Expert ,
Apr 27, 2019 Apr 27, 2019

Copy link to clipboard

Copied

Why not use event.rc in the Keystroke event to reject invalid values, instead of changing them?

Votes

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
Advocate ,
Apr 28, 2019 Apr 28, 2019

Copy link to clipboard

Copied

LATEST

Would work as well.

Votes

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