Skip to content

Commit

Permalink
Merge pull request #17247 from calixteman/bug1863910
Browse files Browse the repository at this point in the history
Don't avoid to execute the Blur callback when blurring a text field (bug 1863910)
  • Loading branch information
calixteman authored Nov 9, 2023
2 parents 42f3d57 + ec396c2 commit f1122f0
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/display/annotation_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1288,7 +1288,9 @@ class TextWidgetAnnotationElement extends WidgetAnnotationElement {
}
elementData.lastCommittedValue = target.value;
elementData.commitKey = 1;
elementData.focused = true;
if (!this.data.actions?.Focus) {
elementData.focused = true;
}
});

element.addEventListener("updatefromsandbox", jsEvent => {
Expand Down Expand Up @@ -1397,7 +1399,9 @@ class TextWidgetAnnotationElement extends WidgetAnnotationElement {
if (!elementData.focused || !event.relatedTarget) {
return;
}
elementData.focused = false;
if (!this.data.actions?.Blur) {
elementData.focused = false;
}
const { value } = event.target;
elementData.userValue = value;
if (elementData.lastCommittedValue !== value) {
Expand Down
42 changes: 42 additions & 0 deletions test/integration/scripting_spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2183,4 +2183,46 @@ describe("Interaction", () => {
);
});
});

describe("Textfield with a Blur callback", () => {
let pages;
let otherPages;

beforeAll(async () => {
otherPages = await Promise.all(
global.integrationSessions.map(async session =>
session.browser.newPage()
)
);
pages = await loadAndWait("bug1863910.pdf", getSelector("25R"));
});

afterAll(async () => {
await closePages(pages);
await Promise.all(otherPages.map(page => page.close()));
});

it("must check that blur callback is called", async () => {
await Promise.all(
pages.map(async ([browserName, page], i) => {
await page.waitForFunction(
"window.PDFViewerApplication.scriptingReady === true"
);

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

await page.waitForFunction(
sel => document.querySelector(sel).value !== "",
{},
getSelector("26R")
);

const text = await page.$eval(getSelector("26R"), el => el.value);
expect(text).withContext(`In ${browserName}`).toEqual("hello");
})
);
});
});
});
2 changes: 1 addition & 1 deletion test/pdfs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -618,4 +618,4 @@
!issue17065.pdf
!issue17069.pdf
!issue17215.pdf

!bug1863910.pdf
Binary file added test/pdfs/bug1863910.pdf
Binary file not shown.

0 comments on commit f1122f0

Please sign in to comment.