Skip to main content
MarkWalsh
Inspiring
March 23, 2017
Question

Debugging Javascript on IOS

  • March 23, 2017
  • 1 reply
  • 1237 views

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.

This topic has been closed for replies.

1 reply

Joel Geraci
Community Expert
Community Expert
March 23, 2017

Can you post the PDF somewhere?

MarkWalsh
MarkWalshAuthor
Inspiring
March 24, 2017

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.

MarkWalsh
MarkWalshAuthor
Inspiring
March 24, 2017

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.