Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[api-minor] Include export value for checkboxes #9874

Merged
merged 1 commit into from
Aug 3, 2018

Conversation

bion
Copy link
Contributor

@bion bion commented Jul 7, 2018

Fixes #8095

U.S. Government forms often use checkboxes as radios by specifying different export values of checkboxes with the same name. See the USCIS I-130 as an example.

Adding the exportValue property to checkbox annotation widgets enables correct rendering of checkbox state for forms that do this.

@bion bion force-pushed the master branch 2 times, most recently from ae59011 to 24749d0 Compare July 9, 2018 17:16
@dbalatero
Copy link

@timvandermeij can this be merged?

if (!isName(this.data.fieldValue)) {
return;
}

var customAppearance = params.dict.get('AP');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change var to const.

var customAppearance = params.dict.get('AP');

if (customAppearance) {
let exportValues = customAppearance.get('D').getKeys();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change let to const.

if (customAppearance) {
let exportValues = customAppearance.get('D').getKeys();

this.data.exportValue = exportValues[0] === 'Off' ?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to have the unit tests extended so that we can be sure that this functionality does not break in the future. They can be found in test/unit/annotation_spec.js.

Copy link
Collaborator

@Snuffleupagus Snuffleupagus Jul 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Furthermore, this patch doesn't appear to do anywhere near enough validation of the structure of this data; doing similar checks as in the _processRadioButton method just below would seem like a requirement to prevent unnecessary future bugs.

@bion bion force-pushed the master branch 6 times, most recently from a69269f to 08c8baa Compare July 24, 2018 20:27
@bion
Copy link
Contributor Author

bion commented Jul 24, 2018

Hi @timvandermeij and @Snuffleupagus, I added an additional test case and validated the structure of the data as per @Snuffleupagus's recommendation to follow the pattern in _processRadioButton.

@timvandermeij
Copy link
Contributor

timvandermeij commented Jul 24, 2018

Code-wise this looks good, but I'm still a bit confused about the functionality. How should this work when the PDF is rendered? I tried making multiple checkboxes with the same name, but that doesn't make them act as radio buttons in HTML (not without some JavaScript at least). I understand that this patch makes the export value available in the API, but I think we should also have a consistent UI for this when we render them. They are rendered at https://github.com/mozilla/pdf.js/blob/master/src/display/annotation_layer.js#L491-L517; note how they have no name.

In short, this patch makes it so that the export value of a checkbox is the state name other than the Off state. This sounds fine to me. My main remaining question is: how do we deal with this when rendering the PDF file? How do other viewers handle this? Note that we can't assume all pages have been loaded since we often only render the visible subset of pages.

@bion
Copy link
Contributor Author

bion commented Jul 25, 2018

@timvandermeij This will not result in a change for the default annotation rendering.

This change is useful in cases when the API consumer is interested in which checkbox has been interacted with by the user. Exposing the export value answers the question of "what is the semantic meaning of this checkbox".

Our use-case at Boundless is an example of how this is useful. In our UI the user's interactions with the annotation layer are used to generate PDFs with the AcroForm fields filled out. If you look at the USCIS I-130 you'll see that question 1 on page 1 is a set of four checkboxes, all with the same field name, but each with a different export value. Exposing the export value to the annotation layer allows us to provide a UI that can interpret the semantics of the user's interaction with those checkboxes.

@timvandermeij
Copy link
Contributor

timvandermeij commented Jul 25, 2018

Thank you for the clarification. In the USCIS I-130 PDF file, it mentions "Select only one box" for question 1 on page 1. To me this implies that the user could in fact select multiple, but is asked to only select one. Is it therefore OK to not change the default rendering and just render multiple checkboxes that may be checked, and leave it up to the API consumer to be able to work with multiple selections if the user does so? I.e., we don't have to enforce the "act as radio buttons" part in the UI; is that what other viewers do?

@timvandermeij
Copy link
Contributor

Moreover, could you amend the commit message (using git commit --amend) to [api-minor] Include export value for checkboxes? This makes it easier to see in the logs that an API change was made.

@timvandermeij timvandermeij changed the title Include export value for checkboxes [api-minor] Include export value for checkboxes Jul 25, 2018
@bion
Copy link
Contributor Author

bion commented Jul 28, 2018

@timvandermeij Updated the commit message per your instructions. Re: the checked button behavior, the USCIS I-130 PDF is often printed on paper which is likely the reasoning behind their explicit instructions.

I.e., we don't have to enforce the "act as radio buttons" part in the UI; is that what other viewers do?

Adobe Acrobat and Adobe Reader enforce the radio-like behavior but macOS Preview and Google Chrome do not. Given the discrepancy there I think leaving it up to the API consumer makes good sense.

@timvandermeij
Copy link
Contributor

/botio test

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

Command cmd_test from @timvandermeij received. Current queue size: 0

Live output at: http://54.67.70.0:8877/c6cc2b091ea4664/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

Command cmd_test from @timvandermeij received. Current queue size: 0

Live output at: http://54.215.176.217:8877/7a1e788342eb72b/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Success

Full output at http://54.67.70.0:8877/c6cc2b091ea4664/output.txt

Total script time: 19.53 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Regression tests: Passed

@pdfjsbot
Copy link

From: Bot.io (Windows)


Success

Full output at http://54.215.176.217:8877/7a1e788342eb72b/output.txt

Total script time: 26.85 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Regression tests: Passed

@timvandermeij timvandermeij merged commit f19ee12 into mozilla:master Aug 3, 2018
@timvandermeij
Copy link
Contributor

Looks good. Thank you for your contribution!

@bion
Copy link
Contributor Author

bion commented Aug 7, 2018

@timvandermeij thanks for supporting the change and getting it in!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants