Debugging Javascript on IOS
Copy link to clipboard
Copied
I'm having problems with a PDF form in Acrobat Reader on IOS. There's a function to set a checkbox value based on which range a field's value is within. There are 3 ranges (55 or less; more than 55 up to 85; more than 85). The corresponding values in the checkboxes are 'A', 'B', 'C' (they originally had the range description, but I simplified it to a single letter for debugging purposes). If the value is 0 then I set the checkbox to 'Off'
Everything works properly in acrobat, but on IOS, it seems to be completely intermittent. I added a field to create my own 'debugger' on iOS, and I'm populating it with the values that of the field, the range value that needs to be set in the checkbox, and the actual value of the checkbox.
Value: 60
Range Value: "B"
Checkbox Value: "B"
Each line is added to the text field right after the variable or checkbox value is set in the function. On IOS, the checkbox is either getting set to 'Off' despite the fact that the range value is 'B' (or whatever the actual value is), and sometimes it will show a completely different value than the variable it's getting set to:
Value: 60
Range Value: "B"
Checkbox Value: "A"
This is the code I am using:
...
debugText = debugText + 'Range Value: "' + rangeValue + '"\r'
CheckboxField.value = rangeValue
debugText = debugText + 'Checkbox Value: "' + CheckboxField.value + '"\r'
...
So I don't understand how the checkbox could be 'A' when it gets set to 'B' in the line of code directly before it. This was the first thing I typed in when I opened the empty PDF on the iPad, so it can't be picking up an old value. If anything, I could at least understand if the checkbox value was 'Off', since it was an empty form and that was the value before I started typing.
I have tried activating the code in the field's 'Blur' event, 'Calculate' event, and 'Validate' event, and neither seems to work.
Unfortunately, I can't debug easily on IOS, I have to keep updating the file on my computer, uploading it to the iPad, then testing, which is extremely time consuming. Is there any way to remotely debug a PDF on IOS, or does anyone have any idea why this isn't working, or what I can do to make this work.
Copy link to clipboard
Copied
Can you post the PDF somewhere?
Copy link to clipboard
Copied
I can't post the actual form, but I'll see if I can find the time to create a small test file that I can post.
Copy link to clipboard
Copied
I made a test file, but I don't have anywhere to upload it to. (Not interested in signing up for any site, or giving my email to possibly get spammed later)
I have created a test file with 5 fields (textbox:'Weight.KG', textbox:'ipadDebugger', and 3 checkboxes 'cbRange' with values 'A', 'B', and 'C'). I have simplified the code to the following, which I am activating in the weight textbox's 'calculate' event:
function updateCheckboxes() {
var weight = 0;
var rangeValue = 'Off';
weight = this.getField('Weight.KG').value;
var debugText = 'Value: ' + weight + '\r';
if (weight > 85) {
rangeValue = 'C';
} else if (weight > 55) {
rangeValue = 'B';
} else if (weight > 0) {
rangeValue = 'A';
}
debugText = debugText + 'Range Value: "' + rangeValue + '"\r';
this.getField('cbRange').value = rangeValue;
debugText = debugText + 'Checkbox Value: "' + this.getField('cbRange').value + '"\r';
this.getField('ipadDebugger').value = debugText;
}
This code works in Acrobat on my computer, but not on the iPad. When I enter a weight of 50, I get Range value 'A', but checkbox value 'C'. A weight of 57 gets Range value 'B', and checkbox value 'Off'. A weight of 90 gets Range value 'C', and checkbox value 'C'. These values don't seem to be consistent either, I seem to get different results each time.
Copy link to clipboard
Copied
You already have an Adobe account, so you can use Adobe's Document Cloud to share your document: Share Documents via Adobe's Document Cloud - KHKonsulting LLC
Copy link to clipboard
Copied
Copy link to clipboard
Copied
You might want to consider a switch statement rather than the if / else if
J-
Copy link to clipboard
Copied
I originally had a switch statement, that was one of the things I had changed during my testing to see if that had any effect on the issue, but it didn't.
Copy link to clipboard
Copied
It doesn't work for me in Acrobat (9.5.5). The error in the console is:
InvalidSetError: Set not possible, invalid or unknown.
Field.value:62:Field Weight.KG:Calculate
You might want to try it without using any document-level functions. Last time I checked, which was a while ago, they were not supported in the mobile versions of Reader.
Copy link to clipboard
Copied
I've used document level functions before without any problems in IOS, so I don't think this is the issue, but I'll check it to see if it has any different effect.
Copy link to clipboard
Copied
I just re-read this more slowly. You're probably having difficulty because you can't have a a calculation script in a field that you're inputting text. Add your calculation to the 'Weight.KG' field format script.
Copy link to clipboard
Copied
I originally had the code in the 'Validate' script, and the same issues were occurring there as well, so that's when I decided to try the calculate event. I'll put the code back there to see if it has any effect, but you can have code in the calculate event of an entry field, at least in the desktop version.
I'll modify my test file with these changes later today to see if it works any differently.

