mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-19 14:48:08 +02:00
Merge pull request #18718 from calixteman/bug1916714
[JS] Let AFSpecial_KeystrokeEx match a format without 'decoration' (bug 1916714)
This commit is contained in:
commit
95cd848e3b
2 changed files with 151 additions and 5 deletions
|
@ -560,6 +560,22 @@ class AForm {
|
|||
}
|
||||
|
||||
AFSpecial_KeystrokeEx(cMask) {
|
||||
const event = globalThis.event;
|
||||
|
||||
// Simplify the format string by removing all characters that are not
|
||||
// specific to the format because the user could enter 1234567 when the
|
||||
// format is 999-9999.
|
||||
const simplifiedFormatStr = cMask.replaceAll(/[^9AOX]/g, "");
|
||||
this.#AFSpecial_KeystrokeEx_helper(simplifiedFormatStr, false);
|
||||
if (event.rc) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.rc = true;
|
||||
this.#AFSpecial_KeystrokeEx_helper(cMask, true);
|
||||
}
|
||||
|
||||
#AFSpecial_KeystrokeEx_helper(cMask, warn) {
|
||||
if (!cMask) {
|
||||
return;
|
||||
}
|
||||
|
@ -605,20 +621,26 @@ class AForm {
|
|||
const err = `${GlobalConstants.IDS_INVALID_VALUE} = "${cMask}"`;
|
||||
|
||||
if (value.length > cMask.length) {
|
||||
this._app.alert(err);
|
||||
if (warn) {
|
||||
this._app.alert(err);
|
||||
}
|
||||
event.rc = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.willCommit) {
|
||||
if (value.length < cMask.length) {
|
||||
this._app.alert(err);
|
||||
if (warn) {
|
||||
this._app.alert(err);
|
||||
}
|
||||
event.rc = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_checkValidity(value, cMask)) {
|
||||
this._app.alert(err);
|
||||
if (warn) {
|
||||
this._app.alert(err);
|
||||
}
|
||||
event.rc = false;
|
||||
return;
|
||||
}
|
||||
|
@ -631,7 +653,9 @@ class AForm {
|
|||
}
|
||||
|
||||
if (!_checkValidity(value, cMask)) {
|
||||
this._app.alert(err);
|
||||
if (warn) {
|
||||
this._app.alert(err);
|
||||
}
|
||||
event.rc = false;
|
||||
}
|
||||
}
|
||||
|
@ -651,7 +675,7 @@ class AForm {
|
|||
case 2:
|
||||
const value = this.AFMergeChange(event);
|
||||
formatStr =
|
||||
value.length > 8 || value.startsWith("(")
|
||||
value.startsWith("(") || (value.length > 7 && /^\p{N}+$/.test(value))
|
||||
? "(999) 999-9999"
|
||||
: "999-9999";
|
||||
break;
|
||||
|
|
|
@ -1571,6 +1571,67 @@ describe("Scripting", function () {
|
|||
send_queue.delete(refId);
|
||||
});
|
||||
|
||||
it("should validate a US phone number with digits only (long) on a keystroke event", async () => {
|
||||
const refId = getId();
|
||||
const data = {
|
||||
objects: {
|
||||
field: [
|
||||
{
|
||||
id: refId,
|
||||
value: "",
|
||||
actions: {
|
||||
Keystroke: [`AFSpecial_Keystroke(2);`],
|
||||
},
|
||||
type: "text",
|
||||
},
|
||||
],
|
||||
},
|
||||
appInfo: { language: "en-US", platform: "Linux x86_64" },
|
||||
calculationOrder: [],
|
||||
dispatchEventName: "_dispatchMe",
|
||||
};
|
||||
sandbox.createSandbox(data);
|
||||
|
||||
let value = "";
|
||||
const changes = "1234567890";
|
||||
let i = 0;
|
||||
|
||||
for (; i < changes.length; i++) {
|
||||
const change = changes.charAt(i);
|
||||
await sandbox.dispatchEventInSandbox({
|
||||
id: refId,
|
||||
value,
|
||||
change,
|
||||
name: "Keystroke",
|
||||
willCommit: false,
|
||||
selStart: i,
|
||||
selEnd: i,
|
||||
});
|
||||
expect(send_queue.has(refId)).toEqual(true);
|
||||
send_queue.delete(refId);
|
||||
value += change;
|
||||
}
|
||||
|
||||
await sandbox.dispatchEventInSandbox({
|
||||
id: refId,
|
||||
value,
|
||||
change: "A",
|
||||
name: "Keystroke",
|
||||
willCommit: false,
|
||||
selStart: i,
|
||||
selEnd: i,
|
||||
});
|
||||
expect(send_queue.has(refId)).toEqual(true);
|
||||
expect(send_queue.get(refId)).toEqual({
|
||||
id: refId,
|
||||
siblings: null,
|
||||
value,
|
||||
selRange: [i, i],
|
||||
});
|
||||
|
||||
send_queue.delete(refId);
|
||||
});
|
||||
|
||||
it("should validate a US phone number (short) on a keystroke event", async () => {
|
||||
const refId = getId();
|
||||
const data = {
|
||||
|
@ -1631,6 +1692,67 @@ describe("Scripting", function () {
|
|||
|
||||
send_queue.delete(refId);
|
||||
});
|
||||
|
||||
it("should validate a US phone number with digits only (short) on a keystroke event", async () => {
|
||||
const refId = getId();
|
||||
const data = {
|
||||
objects: {
|
||||
field: [
|
||||
{
|
||||
id: refId,
|
||||
value: "",
|
||||
actions: {
|
||||
Keystroke: [`AFSpecial_Keystroke(2);`],
|
||||
},
|
||||
type: "text",
|
||||
},
|
||||
],
|
||||
},
|
||||
appInfo: { language: "en-US", platform: "Linux x86_64" },
|
||||
calculationOrder: [],
|
||||
dispatchEventName: "_dispatchMe",
|
||||
};
|
||||
sandbox.createSandbox(data);
|
||||
|
||||
let value = "";
|
||||
const changes = "1234567";
|
||||
let i = 0;
|
||||
|
||||
for (; i < changes.length; i++) {
|
||||
const change = changes.charAt(i);
|
||||
await sandbox.dispatchEventInSandbox({
|
||||
id: refId,
|
||||
value,
|
||||
change,
|
||||
name: "Keystroke",
|
||||
willCommit: false,
|
||||
selStart: i,
|
||||
selEnd: i,
|
||||
});
|
||||
expect(send_queue.has(refId)).toEqual(true);
|
||||
send_queue.delete(refId);
|
||||
value += change;
|
||||
}
|
||||
|
||||
await sandbox.dispatchEventInSandbox({
|
||||
id: refId,
|
||||
value,
|
||||
change: "A",
|
||||
name: "Keystroke",
|
||||
willCommit: false,
|
||||
selStart: i,
|
||||
selEnd: i,
|
||||
});
|
||||
expect(send_queue.has(refId)).toEqual(true);
|
||||
expect(send_queue.get(refId)).toEqual({
|
||||
id: refId,
|
||||
siblings: null,
|
||||
value,
|
||||
selRange: [i, i],
|
||||
});
|
||||
|
||||
send_queue.delete(refId);
|
||||
});
|
||||
});
|
||||
|
||||
describe("eMailValidate", function () {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue