[Annotation] Send correctly the updated values to the JS sandbox
This commit is contained in:
parent
ff9d21ff0e
commit
20fd9099f8
@ -1065,7 +1065,7 @@ class TextWidgetAnnotationElement extends WidgetAnnotationElement {
|
||||
const elementData = {
|
||||
userValue: textContent,
|
||||
formattedValue: null,
|
||||
valueOnFocus: "",
|
||||
lastCommittedValue: null,
|
||||
};
|
||||
|
||||
if (this.data.multiLine) {
|
||||
@ -1122,10 +1122,11 @@ class TextWidgetAnnotationElement extends WidgetAnnotationElement {
|
||||
|
||||
if (this.enableScripting && this.hasJSActions) {
|
||||
element.addEventListener("focus", event => {
|
||||
const { target } = event;
|
||||
if (elementData.userValue) {
|
||||
event.target.value = elementData.userValue;
|
||||
target.value = elementData.userValue;
|
||||
}
|
||||
elementData.valueOnFocus = event.target.value;
|
||||
elementData.lastCommittedValue = target.value;
|
||||
});
|
||||
|
||||
element.addEventListener("updatefromsandbox", jsEvent => {
|
||||
@ -1207,9 +1208,10 @@ class TextWidgetAnnotationElement extends WidgetAnnotationElement {
|
||||
return;
|
||||
}
|
||||
const { value } = event.target;
|
||||
if (elementData.valueOnFocus === value) {
|
||||
if (elementData.lastCommittedValue === value) {
|
||||
return;
|
||||
}
|
||||
elementData.lastCommittedValue = value;
|
||||
// Save the entered value
|
||||
elementData.userValue = value;
|
||||
this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
|
||||
@ -1230,7 +1232,10 @@ class TextWidgetAnnotationElement extends WidgetAnnotationElement {
|
||||
element.addEventListener("blur", event => {
|
||||
const { value } = event.target;
|
||||
elementData.userValue = value;
|
||||
if (this._mouseState.isDown && elementData.valueOnFocus !== value) {
|
||||
if (
|
||||
this._mouseState.isDown &&
|
||||
elementData.lastCommittedValue !== value
|
||||
) {
|
||||
// Focus out using the mouse: data are committed
|
||||
this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
|
||||
source: this,
|
||||
@ -1250,6 +1255,7 @@ class TextWidgetAnnotationElement extends WidgetAnnotationElement {
|
||||
|
||||
if (this.data.actions?.Keystroke) {
|
||||
element.addEventListener("beforeinput", event => {
|
||||
elementData.lastCommittedValue = null;
|
||||
const { data, target } = event;
|
||||
const { value, selectionStart, selectionEnd } = target;
|
||||
|
||||
|
@ -1598,4 +1598,57 @@ describe("Interaction", () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("in issue15753.pdf", () => {
|
||||
let pages;
|
||||
|
||||
beforeAll(async () => {
|
||||
pages = await loadAndWait("issue15753.pdf", getSelector("27R"));
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await closePages(pages);
|
||||
});
|
||||
|
||||
it("must check field value is correctly updated when committed with ENTER key", async () => {
|
||||
await Promise.all(
|
||||
pages.map(async ([browserName, page]) => {
|
||||
await page.waitForFunction(
|
||||
"window.PDFViewerApplication.scriptingReady === true"
|
||||
);
|
||||
|
||||
await page.type(getSelector("27R"), "abc", {
|
||||
delay: 10,
|
||||
});
|
||||
await page.keyboard.press("Enter");
|
||||
await page.waitForFunction(`${getQuerySelector("28R")}.value !== ""`);
|
||||
let value = await page.$eval(getSelector("28R"), el => el.value);
|
||||
expect(value).withContext(`In ${browserName}`).toEqual("abc");
|
||||
|
||||
await page.type(getSelector("27R"), "def", {
|
||||
delay: 10,
|
||||
});
|
||||
|
||||
await page.keyboard.press("Enter");
|
||||
await page.waitForFunction(
|
||||
`${getQuerySelector("28R")}.value !== "abc"`
|
||||
);
|
||||
value = await page.$eval(getSelector("28R"), el => el.value);
|
||||
expect(value).withContext(`In ${browserName}`).toEqual("abcdef");
|
||||
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("A");
|
||||
await page.keyboard.up("Control");
|
||||
await page.keyboard.press("Backspace");
|
||||
|
||||
await page.keyboard.press("Enter");
|
||||
await page.waitForFunction(
|
||||
`${getQuerySelector("28R")}.value !== "abcdef"`
|
||||
);
|
||||
value = await page.$eval(getSelector("28R"), el => el.value);
|
||||
expect(value).withContext(`In ${browserName}`).toEqual("");
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
1
test/pdfs/.gitignore
vendored
1
test/pdfs/.gitignore
vendored
@ -558,3 +558,4 @@
|
||||
!issue15690.pdf
|
||||
!bug1802888.pdf
|
||||
!issue15759.pdf
|
||||
!issue15753.pdf
|
||||
|
BIN
test/pdfs/issue15753.pdf
Executable file
BIN
test/pdfs/issue15753.pdf
Executable file
Binary file not shown.
Loading…
Reference in New Issue
Block a user