From e868ab0051b65b83498830019fd5b73b66c43c35 Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Tue, 20 Apr 2021 18:32:23 +0200 Subject: [PATCH] Update all the text widgets having the same name with the same value --- src/display/annotation_layer.js | 20 +++++++++++++++- test/integration/annotation_spec.js | 35 ++++++++++++++++++++++++++++ test/pdfs/.gitignore | 1 + test/pdfs/issue13271.pdf | Bin 0 -> 6370 bytes 4 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 test/pdfs/issue13271.pdf 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 0000000000000000000000000000000000000000..64e3345cc33d10733f11669ab20437119da34e8e GIT binary patch literal 6370 zcmeHLc~leU76)ZB5LB>~O&y~kipeaQtWBa2h$2J~P+V%sB$+_WGBFtlTB$28tyL=; zY+Xu~YDIe#<+#)*MFqvRh+BPX>yEW`IUcKhtu60M0upQNd!F-p&iljUWKL$jd+&Ge z@BY5;yL02RQWR{I!)L}_yZ+5-CIjU|2t=tTGbIu@LvJPtt9}}(g-|#H;&TNEoC%>q zI2A%MJ_3&dk8>eD!V|(HpotL9Lm-roPm;-)q*?2<0eSl{85r6*M+&K-v}6`xHQB(7 za>`g_GTR^=&a#qPy@sZ&U@DmmR_Kj1X@wO=f+pQ6a9YYlNvcAQ^MzOnUyks3IIa-l z3JgP&xhWzfNhnB7l1UVz)FcGwiIRju0Vc!+!el&2fTbkyctSaXh>~TK;54(AESU%b zM=|G(j)G7ga4;LrAk77IA%qK^-V{3n6~WmQMMJ2-HJ$^YfiNMQJJmwM8-50y%-Vss4)sTnqV3TMHBfUp_G7=mKQ1Je*>U3gp6`8MAm z#HTVd;4+f|uxnRtN6|(TR=UJW>X;0K$%um5}_;iU^2ISTUH4F)fWj3j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