From a334a21a1d6324637f4df37a29dfd087fd4559b3 Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Fri, 24 Jun 2022 14:23:06 +0200 Subject: [PATCH] [JS] Update siblings when a field is updated after a calculation (#15092) --- src/scripting_api/doc.js | 1 + src/scripting_api/event.js | 7 ++++ test/integration/scripting_spec.js | 50 ++++++++++++++++++++++++++++- test/pdfs/.gitignore | 1 + test/pdfs/issue15092.pdf | Bin 0 -> 17012 bytes 5 files changed, 58 insertions(+), 1 deletion(-) create mode 100755 test/pdfs/issue15092.pdf diff --git a/src/scripting_api/doc.js b/src/scripting_api/doc.js index 153264393..4440d5ca5 100644 --- a/src/scripting_api/doc.js +++ b/src/scripting_api/doc.js @@ -1151,6 +1151,7 @@ class Doc extends PDFObject { field.obj.value = field.obj.defaultValue; this._send({ id: field.obj._id, + siblings: field.obj._siblings, value: field.obj.defaultValue, formattedValue: null, selRange: [0, 0], diff --git a/src/scripting_api/event.js b/src/scripting_api/event.js index b0f3c26f7..e684d37ce 100644 --- a/src/scripting_api/event.js +++ b/src/scripting_api/event.js @@ -163,6 +163,7 @@ class EventDispatcher { } source.obj._send({ id: source.obj._id, + siblings: source.obj._siblings, value, selRange: [selStart, selEnd], }); @@ -170,6 +171,7 @@ class EventDispatcher { } else if (!event.willCommit) { source.obj._send({ id: source.obj._id, + siblings: source.obj._siblings, value: savedChange.value, selRange: [savedChange.selStart, savedChange.selEnd], }); @@ -178,6 +180,7 @@ class EventDispatcher { // so just clear the field. source.obj._send({ id: source.obj._id, + siblings: source.obj._siblings, value: "", formattedValue: null, selRange: [0, 0], @@ -193,6 +196,7 @@ class EventDispatcher { if (this.runActions(source, source, event, "Format")) { source.obj._send({ id: source.obj._id, + siblings: source.obj._siblings, formattedValue: event.value?.toString?.(), }); } @@ -215,6 +219,7 @@ class EventDispatcher { source.obj._send({ id: source.obj._id, + siblings: source.obj._siblings, value: savedValue, formattedValue, }); @@ -223,6 +228,7 @@ class EventDispatcher { // The value is not valid. source.obj._send({ id: source.obj._id, + siblings: source.obj._siblings, value: "", formattedValue: null, selRange: [0, 0], @@ -320,6 +326,7 @@ class EventDispatcher { target.obj._send({ id: target.obj._id, + siblings: target.obj._siblings, value: savedValue, formattedValue, }); diff --git a/test/integration/scripting_spec.js b/test/integration/scripting_spec.js index 5b36303aa..2405c5608 100644 --- a/test/integration/scripting_spec.js +++ b/test/integration/scripting_spec.js @@ -1413,7 +1413,7 @@ describe("Interaction", () => { await closePages(pages); }); - it("must check that data-annotation-rotation is correc", async () => { + it("must check that data-annotation-rotation is correct", async () => { await Promise.all( pages.map(async ([browserName, page]) => { await page.waitForFunction( @@ -1444,4 +1444,52 @@ describe("Interaction", () => { ); }); }); + + describe("in issue15092.pdf", () => { + let pages; + + beforeAll(async () => { + pages = await loadAndWait("issue15092.pdf", getSelector("39R")); + }); + + afterAll(async () => { + await closePages(pages); + }); + + it("must check that a values is correctly updated on a field and its siblings", async () => { + await Promise.all( + pages.map(async ([browserName, page]) => { + await page.waitForFunction( + "window.PDFViewerApplication.scriptingReady === true" + ); + + await clearInput(page, getSelector("39R")); + await page.type(getSelector("39R"), "123", { delay: 10 }); + + const prevTotal = await page.$eval( + getSelector("43R"), + el => el.value + ); + + await clearInput(page, getSelector("42R")); + await page.type(getSelector("42R"), "456", { delay: 10 }); + + await page.click(getSelector("45R")); + + await page.waitForFunction( + `${getQuerySelector("43R")}.value !== "${prevTotal}"` + ); + await page.waitForFunction( + `${getQuerySelector("46R")}.value !== "${prevTotal}"` + ); + + let total = await page.$eval(getSelector("43R"), el => el.value); + expect(total).withContext(`In ${browserName}`).toEqual("579.00"); + + total = await page.$eval(getSelector("46R"), el => el.value); + expect(total).withContext(`In ${browserName}`).toEqual("579.00"); + }) + ); + }); + }); }); diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index 70817f3a2..5d1d18e73 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -529,3 +529,4 @@ !bug1724918.pdf !issue15053.pdf !bug1675139.pdf +!issue15092.pdf diff --git a/test/pdfs/issue15092.pdf b/test/pdfs/issue15092.pdf new file mode 100755 index 0000000000000000000000000000000000000000..1f1442304cb1e96d3a972ea896ca1a2ad3569b0a GIT binary patch literal 17012 zcmeHv2UJwawl+yZlR=_^LzLW^1|&$%IcFMZf&xuwq7oEI3JOS2qGSY>pn?Pm0s@kQ z83hv{s3buV(El{b$lPJ(&VB2>wf=sH!djmz1IxeD!*8 zlpX@d05AaWbd+9B4yxVpxcU<4ci zhiU>g02+w_qh;(A6zFl@E<`cFAO6upkW#0VefS0#FfPxzO z;aohN33xvMj!;m5s(W}6aDGsAPb>lVBMVeZ)kaQAU0Gcfg@hpyY8V6zrKTiaS60_iaKr4ysAal$v z2yM00Pd+O-`{C8`eqI2`Qeyk+;Rsk4ECCB3w;l}w2%aG0{ed5`hFCZ79**9M+iGDI zFs&!v?H9S>GQTiV^7h6P`~l<-W~ku32{>=?8Sz7yiXYxb86Ru|lY{}p|59)S7-D3= z&w7PH*2M z0rbzhz#LEjnppL%^k}d$#Cx!p8T#R!O>hJoC^#rUO>w~lkjEh531FuKU_V$+MCBI% z2vD2t(L#Br25>Y{OT?CXM97Kw5eJcml;?(Lwv=&6bG3!|<`UkDrk|4`BZsD&R6Vgd1nD4Rl{ zTgAW;fT=442Dm{GfRrQ}Ol0Z;5e91r69G(*LexwlMi4bU7051(L+t1{{{be_sDCCV z2qZ!ri9r4>WDx%&w*0e^LH#Xch&}e_DD@w32J;W?M}H3!)c**Re>PjB{}x+_WBPy2 zmVY)fe~&XezASh7Xi@j@^CtiZY1sBe1b!x>!H-xZ>c?aO&J`vEuU~V8`-?Z$SpR2I zESqB4Cu*jxqXeiUvwL0C<3H$R3h6r^t{3VjxX0JZ6bob&jC>8>yi*5wSSNeRJbE|2 zB4iasQr+rQ{Wy$PyAhxxaI3Pbv3KM%u*k{mHA)hY(sXJ%yLdIK8&`HnDOJrXiIbpj z^b|N}$08sZ$68w|eBi4yjH9vjw34ec>qY9~hbQ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