Skip to content

Commit

Permalink
Merge pull request #16864 from calixteman/issue16863
Browse files Browse the repository at this point in the history
Don't reset all fields when the resetForm argument is an array
  • Loading branch information
calixteman authored Aug 24, 2023
2 parents 08f26be + 24b480f commit 62a294b
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 6 deletions.
6 changes: 6 additions & 0 deletions src/core/annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -3190,6 +3190,9 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
this._streams.push(this.uncheckedAppearance);
}
this._fallbackFontDict = this.fallbackFontDict;
if (this.data.defaultFieldValue === null) {
this.data.defaultFieldValue = "Off";
}
}

_processRadioButton(params) {
Expand Down Expand Up @@ -3238,6 +3241,9 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
this._streams.push(this.uncheckedAppearance);
}
this._fallbackFontDict = this.fallbackFontDict;
if (this.data.defaultFieldValue === null) {
this.data.defaultFieldValue = "Off";
}
}

_processPushButton(params) {
Expand Down
6 changes: 1 addition & 5 deletions src/display/annotation_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,11 +373,7 @@ class AnnotationElement {
event.target.title = event.detail.userName;
},
readonly: event => {
if (event.detail.readonly) {
event.target.setAttribute("readonly", "");
} else {
event.target.removeAttribute("readonly");
}
event.target.disabled = event.detail.readonly;
},
required: event => {
this._setRequired(event.target, event.detail.required);
Expand Down
2 changes: 1 addition & 1 deletion src/scripting_api/doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,7 @@ class Doc extends PDFObject {

resetForm(aFields = null) {
// Handle the case resetForm({ aFields: ... })
if (aFields && typeof aFields === "object") {
if (aFields && typeof aFields === "object" && !Array.isArray(aFields)) {
aFields = aFields.aFields;
}

Expand Down
56 changes: 56 additions & 0 deletions test/integration/scripting_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2098,4 +2098,60 @@ describe("Interaction", () => {
);
});
});

describe("in issue16863.pdf", () => {
let pages;

beforeAll(async () => {
pages = await loadAndWait("issue16863.pdf", getSelector("334R"));
});

afterAll(async () => {
await closePages(pages);
});

it("must check that checkboxes are correctly resetted", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
await page.waitForFunction(
"window.PDFViewerApplication.scriptingReady === true"
);

let readonly = await page.$eval(
getSelector("353R"),
el => el.disabled
);
expect(readonly).withContext(`In ${browserName}`).toEqual(true);
await page.click(getSelector("334R"));
await page.waitForTimeout(10);

readonly = await page.$eval(getSelector("353R"), el => el.disabled);
expect(readonly).withContext(`In ${browserName}`).toEqual(true);
await page.click(getSelector("351R"));
await page.waitForTimeout(10);

readonly = await page.$eval(getSelector("353R"), el => el.disabled);
expect(readonly).withContext(`In ${browserName}`).toEqual(true);
await page.click(getSelector("352R"));
await page.waitForTimeout(10);

readonly = await page.$eval(getSelector("353R"), el => el.disabled);
expect(readonly).withContext(`In ${browserName}`).toEqual(false);

await page.click(getSelector("353R"));
await page.waitForTimeout(10);

let checked = await page.$eval(getSelector("353R"), el => el.checked);
expect(checked).withContext(`In ${browserName}`).toEqual(true);
await page.click(getSelector("334R"));
await page.waitForTimeout(10);

readonly = await page.$eval(getSelector("353R"), el => el.disabled);
expect(readonly).withContext(`In ${browserName}`).toEqual(true);
checked = await page.$eval(getSelector("353R"), el => el.checked);
expect(checked).withContext(`In ${browserName}`).toEqual(false);
})
);
});
});
});
1 change: 1 addition & 0 deletions test/pdfs/issue16863.pdf.link
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/mozilla/pdf.js/files/12422360/4422-84.pdf
7 changes: 7 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8119,5 +8119,12 @@
"rotation": 0
}
}
},
{
"id": "issue16863",
"file": "pdfs/issue16863.pdf",
"md5": "af8abe281721f92a0d46646969f061de",
"link": true,
"type": "other"
}
]

0 comments on commit 62a294b

Please sign in to comment.