[JS] Let AFSpecial_KeystrokeEx match a format without 'decoration' (bug 1916714)
It'll let the user enter 1234567 instead of 123-4567 for example. It works like this in other pdf viewers.
This commit is contained in:
parent
a1b45d6e69
commit
bae32b4fd2
@ -560,6 +560,22 @@ class AForm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
AFSpecial_KeystrokeEx(cMask) {
|
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) {
|
if (!cMask) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -605,20 +621,26 @@ class AForm {
|
|||||||
const err = `${GlobalConstants.IDS_INVALID_VALUE} = "${cMask}"`;
|
const err = `${GlobalConstants.IDS_INVALID_VALUE} = "${cMask}"`;
|
||||||
|
|
||||||
if (value.length > cMask.length) {
|
if (value.length > cMask.length) {
|
||||||
this._app.alert(err);
|
if (warn) {
|
||||||
|
this._app.alert(err);
|
||||||
|
}
|
||||||
event.rc = false;
|
event.rc = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.willCommit) {
|
if (event.willCommit) {
|
||||||
if (value.length < cMask.length) {
|
if (value.length < cMask.length) {
|
||||||
this._app.alert(err);
|
if (warn) {
|
||||||
|
this._app.alert(err);
|
||||||
|
}
|
||||||
event.rc = false;
|
event.rc = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_checkValidity(value, cMask)) {
|
if (!_checkValidity(value, cMask)) {
|
||||||
this._app.alert(err);
|
if (warn) {
|
||||||
|
this._app.alert(err);
|
||||||
|
}
|
||||||
event.rc = false;
|
event.rc = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -631,7 +653,9 @@ class AForm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!_checkValidity(value, cMask)) {
|
if (!_checkValidity(value, cMask)) {
|
||||||
this._app.alert(err);
|
if (warn) {
|
||||||
|
this._app.alert(err);
|
||||||
|
}
|
||||||
event.rc = false;
|
event.rc = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -651,7 +675,7 @@ class AForm {
|
|||||||
case 2:
|
case 2:
|
||||||
const value = this.AFMergeChange(event);
|
const value = this.AFMergeChange(event);
|
||||||
formatStr =
|
formatStr =
|
||||||
value.length > 8 || value.startsWith("(")
|
value.startsWith("(") || (value.length > 7 && /^\p{N}+$/.test(value))
|
||||||
? "(999) 999-9999"
|
? "(999) 999-9999"
|
||||||
: "999-9999";
|
: "999-9999";
|
||||||
break;
|
break;
|
||||||
|
|||||||
@ -1571,6 +1571,67 @@ describe("Scripting", function () {
|
|||||||
send_queue.delete(refId);
|
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 () => {
|
it("should validate a US phone number (short) on a keystroke event", async () => {
|
||||||
const refId = getId();
|
const refId = getId();
|
||||||
const data = {
|
const data = {
|
||||||
@ -1631,6 +1692,67 @@ describe("Scripting", function () {
|
|||||||
|
|
||||||
send_queue.delete(refId);
|
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 () {
|
describe("eMailValidate", function () {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user