diff --git a/src/display/annotation_layer.js b/src/display/annotation_layer.js index e7dbf59bd5527..220974bf1000c 100644 --- a/src/display/annotation_layer.js +++ b/src/display/annotation_layer.js @@ -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 => { @@ -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) { diff --git a/test/integration/scripting_spec.mjs b/test/integration/scripting_spec.mjs index 83d5bfeeb687c..52b60b1dbd237 100644 --- a/test/integration/scripting_spec.mjs +++ b/test/integration/scripting_spec.mjs @@ -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"); + }) + ); + }); + }); }); diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index 4101b2eb05192..d63f3d7d9d203 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -618,4 +618,4 @@ !issue17065.pdf !issue17069.pdf !issue17215.pdf - +!bug1863910.pdf diff --git a/test/pdfs/bug1863910.pdf b/test/pdfs/bug1863910.pdf new file mode 100755 index 0000000000000..3db6eded51d33 Binary files /dev/null and b/test/pdfs/bug1863910.pdf differ