diff --git a/src/display/annotation_layer.js b/src/display/annotation_layer.js index 57370d358..c2a4c8508 100644 --- a/src/display/annotation_layer.js +++ b/src/display/annotation_layer.js @@ -625,6 +625,18 @@ class TextWidgetAnnotationElement extends WidgetAnnotationElement { super(parameters, { isRenderable }); } + setPropertyOnSiblings(base, key, value, keyInStorage) { + const storage = this.annotationStorage; + for (const element of document.getElementsByName(base.name)) { + if (element !== base) { + element[key] = value; + const data = Object.create(null); + data[keyInStorage] = value; + storage.setValue(element.getAttribute("id"), data); + } + } + } + render() { const storage = this.annotationStorage; const id = this.data.id; @@ -660,8 +672,14 @@ class TextWidgetAnnotationElement extends WidgetAnnotationElement { elementData.userValue = textContent; element.setAttribute("id", id); - element.addEventListener("input", function (event) { + element.addEventListener("input", event => { storage.setValue(id, { value: event.target.value }); + this.setPropertyOnSiblings( + element, + "value", + event.target.value, + "value" + ); }); let blurListener = event => { diff --git a/test/integration/annotation_spec.js b/test/integration/annotation_spec.js index 15f5ec664..bdf3aa4e5 100644 --- a/test/integration/annotation_spec.js +++ b/test/integration/annotation_spec.js @@ -87,3 +87,38 @@ describe("Checkbox annotation", () => { }); }); }); + +describe("Text widget", () => { + describe("issue13271.pdf", () => { + let pages; + + beforeAll(async () => { + pages = await loadAndWait("issue13271.pdf", "[data-annotation-id='24R']"); + }); + + afterAll(async () => { + await closePages(pages); + }); + + it("must update all the fields with the same value", async () => { + const base = "hello world"; + await Promise.all( + pages.map(async ([browserName, page]) => { + await page.type("#\\32 5R", base); + await page.waitForFunction( + `document.querySelector("#\\\\32 4R").value !== ""` + ); + await page.waitForFunction( + `document.querySelector("#\\\\32 6R").value !== ""` + ); + + let text = await page.$eval("#\\32 4R", el => el.value); + expect(text).withContext(`In ${browserName}`).toEqual(base); + + text = await page.$eval("#\\32 6R", el => el.value); + expect(text).withContext(`In ${browserName}`).toEqual(base); + }) + ); + }); + }); +}); diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index 0de249e8c..b4ffe80f7 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -373,6 +373,7 @@ !issue6106.pdf !issue6296.pdf !bug852992_reduced.pdf +!issue13271.pdf !issue6298.pdf !issue6889.pdf !bug1001080.pdf diff --git a/test/pdfs/issue13271.pdf b/test/pdfs/issue13271.pdf new file mode 100644 index 000000000..64e3345cc Binary files /dev/null and b/test/pdfs/issue13271.pdf differ