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

AcroForm: Add support for ResetForm action #14083

Merged
merged 1 commit into from
Sep 30, 2021
Merged

Conversation

calixteman
Copy link
Contributor

@calixteman calixteman marked this pull request as draft September 26, 2021 19:11
Copy link
Collaborator

@Snuffleupagus Snuffleupagus left a comment

Choose a reason for hiding this comment

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

Despite this being marked as a "draft", I figured it couldn't hurt to add a few comments based on cursory look. The overall approach looks reasonable though :-)

src/core/catalog.js Show resolved Hide resolved
src/core/catalog.js Outdated Show resolved Hide resolved
src/core/catalog.js Outdated Show resolved Hide resolved
src/display/annotation_layer.js Show resolved Hide resolved
src/display/annotation_layer.js Outdated Show resolved Hide resolved
@calixteman
Copy link
Contributor Author

@Snuffleupagus, when you'll have time, could you review this PR please ?

Copy link
Collaborator

@Snuffleupagus Snuffleupagus left a comment

Choose a reason for hiding this comment

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

r=me, with the comments addressed and passing tests; thank you!

Comment on lines 570 to 588
if (!this._fieldObjects) {
warn(
`_bindResetFormAction - "resetForm" action not supported, ` +
"ensure that the `fieldObjects` parameter is provided."
);
return;
}

link.className = "internalLink";
const otherClickAction = link.onclick;
link.onclick = () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Depending on the data, you may or may not have set either the href or className at this point. Furthermore, you also need to ensure that a dummy onclick is added in the fallback-case.

All-in-all, can you please make the following changes which I believe should cover all of the cases that could possibly happen here?

Suggested change
if (!this._fieldObjects) {
warn(
`_bindResetFormAction - "resetForm" action not supported, ` +
"ensure that the `fieldObjects` parameter is provided."
);
return;
}
link.className = "internalLink";
const otherClickAction = link.onclick;
link.onclick = () => {
const otherClickAction = link.onclick;
if (!otherClickAction) {
link.href = this.linkService.getAnchorUrl("");
}
link.className = "internalLink";
if (!this._fieldObjects) {
warn(
`_bindResetFormAction - "resetForm" action not supported, ` +
"ensure that the `fieldObjects` parameter is provided."
);
if (!otherClickAction) {
link.onclick = () => false;
}
return;
}
link.onclick = () => {

}
for (const fields of Object.values(this._fieldObjects)) {
for (const field of fields) {
if (include === fieldIds.has(field.id)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: Let's swap the order in this comparison, since the "constant" value should usually be on the right. (Note that a comparison such as if (5 === someVar) { ... } would actually be a linting failure.)

@@ -1217,6 +1338,13 @@ class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement {
}
}

selectElement.addEventListener("resetform", event => {
const defaultValue = this.data.defaultFieldValue;
Array.prototype.forEach.call(selectElement.options, option => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Unless I'm mistaken, I believe that you should be able to iterate through the options with a for...of loop instead. Assuming that works, let's do that instead since it feels nicer than having to use Array.forEach in this way.

  - it aims to fix mozilla#12721.
  - Thanks to PR mozilla#14023, we've now the fieldObjects in the annotation layer so we can easily map fields names on their id if needed.
  - Reset values in the storage, in the JS sandbox and in the visible html elements.
@calixteman
Copy link
Contributor Author

/botio unittest
/botio integrationtest

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

Command cmd_unittest from @calixteman received. Current queue size: 0

Live output at: http://54.193.163.58:8877/c8f732f3159a11d/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

Command cmd_unittest from @calixteman received. Current queue size: 0

Live output at: http://54.241.84.105:8877/1f29a21f3cbc57d/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Success

Full output at http://54.241.84.105:8877/1f29a21f3cbc57d/output.txt

Total script time: 2.81 mins

  • Unit Tests: Passed

@pdfjsbot
Copy link

From: Bot.io (Windows)


Success

Full output at http://54.193.163.58:8877/c8f732f3159a11d/output.txt

Total script time: 6.13 mins

  • Unit Tests: Passed

@calixteman
Copy link
Contributor Author

/botio integrationtest

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

Command cmd_integrationtest from @calixteman received. Current queue size: 0

Live output at: http://54.241.84.105:8877/fb8c254b0a5ffb2/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

Command cmd_integrationtest from @calixteman received. Current queue size: 0

Live output at: http://54.193.163.58:8877/4a30439f4249ed7/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Success

Full output at http://54.241.84.105:8877/fb8c254b0a5ffb2/output.txt

Total script time: 3.77 mins

  • Integration Tests: Passed

@pdfjsbot
Copy link

From: Bot.io (Windows)


Success

Full output at http://54.193.163.58:8877/4a30439f4249ed7/output.txt

Total script time: 6.27 mins

  • Integration Tests: Passed

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.

Add support for ResetForm action
3 participants