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

Explorer ,
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, Macintosh, Windows

Views

383

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 ,
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?

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 ,
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?

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
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.

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
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.

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 ,
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?

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

Copy link to clipboard

Copied

LATEST

Would work as well.

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