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

Why is the blank field script not working in my pdf?

New Here ,
Aug 14, 2017 Aug 14, 2017

I created a template in Scribus and added pdf forms fields before saving it as a pdf. I then opened the pdf in Adobe Acrobat Pro 9 and entered the following scripts in my percentage fields, but neither worked.


if(event.value == 0 | event.value = "") event.value = "";

if( Number(event.value) == 0) event.value = "";


I entered each on their own, but neither worked. I also tried entering them in the "Run custom validation script:" and "Custom Calculation Script" sections and neither worked.

Currently, my form will print out "0.00%" when no value is inputted into said fields. I want the fields to print blank if no value is entered.

Any help is highly appreciated, thanks!

TOPICS
Acrobat SDK and JavaScript , Windows
1.9K
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

correct answers 1 Correct answer

Community Expert , Aug 14, 2017 Aug 14, 2017

You can get pretty good results with pretty simple code, actually... As the custom Format script enter this:

if (event.value) event.value = event.value+"%";

And as the custom validation script enter this:

if (isNaN(Number(event.value))) event.rc = false;

This will basically only allow the user to enter numbers (they could still type non-number characters, but they will be rejected), as well as an empty string, and will add the percentage symbol to any non-empty value.

Translate
Community Expert ,
Aug 14, 2017 Aug 14, 2017

You can't set a Percentage field to be completely empty. Also, there's an error in the first code...

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
New Here ,
Aug 14, 2017 Aug 14, 2017

I see, well then that explains why those scripts didn't work. Is there any other way to prevent the "0.00%" from being printed? Or are percentage fields really that limited?

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 ,
Aug 14, 2017 Aug 14, 2017

The only way is if you wrote your own custom Format, Keystroke and Validation methods. Then you would be able to force an empty value.

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
New Here ,
Aug 14, 2017 Aug 14, 2017

Whoa, that sounds really out of my javascript league atm. I guess for now I'll simply restrict the field to number entries - rather than having it be a percentage field - and place a non-editable "%" text field besides it. If the field is blank, then the only thing that'll print out is the "%" sign which is better than the full "0.00%." Thanks for helping me out.

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 ,
Aug 14, 2017 Aug 14, 2017

You can get pretty good results with pretty simple code, actually... As the custom Format script enter this:

if (event.value) event.value = event.value+"%";

And as the custom validation script enter this:

if (isNaN(Number(event.value))) event.rc = false;

This will basically only allow the user to enter numbers (they could still type non-number characters, but they will be rejected), as well as an empty string, and will add the percentage symbol to any non-empty value.

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
New Here ,
Aug 15, 2017 Aug 15, 2017

This works great, it totally solves my problem, thanks!

Just so I understand, basically the first script says that if something is entered into the field, a % sign should be added to the end of it. In the second script, Number(event.value) converts whatever is entered into the filed to a number. If it truly is a number, then the isNaN(Number(event.value)) returns as false, which then means event.rc = false runs and the number is displayed in the field. If what was entered was not a number, then the if statement would return as true which is why nothing is displayed in such an instance, correct?

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 ,
Aug 15, 2017 Aug 15, 2017

Exactly so.

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 ,
Aug 15, 2017 Aug 15, 2017

Sorry, actually the last statement was wrong.

If isNaN returns true it means the value entered is not a number, and then the value is rejected (by setting event.rc as false).

If it is a number nothing is done and by default the new value is accepted.

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
New Here ,
Aug 16, 2017 Aug 16, 2017
LATEST

Got it, thanks again for all your help.

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