Copy link to clipboard
Copied
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!
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.
Copy link to clipboard
Copied
You can't set a Percentage field to be completely empty. Also, there's an error in the first code...
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
Exactly so.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Got it, thanks again for all your help.