mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-09 09:45:42 +02:00
[JS] Handle correctly choice widgets where the display and the export values are different (issue #15815)
This commit is contained in:
parent
64786b4c93
commit
0c1ec946aa
8 changed files with 155 additions and 30 deletions
|
@ -137,6 +137,7 @@ class EventDispatcher {
|
|||
case "Keystroke":
|
||||
savedChange = {
|
||||
value: event.value,
|
||||
changeEx: event.changeEx,
|
||||
change: event.change,
|
||||
selStart: event.selStart,
|
||||
selEnd: event.selEnd,
|
||||
|
@ -170,6 +171,16 @@ class EventDispatcher {
|
|||
if (event.willCommit) {
|
||||
this.runValidation(source, event);
|
||||
} else {
|
||||
if (source.obj._isChoice) {
|
||||
source.obj.value = savedChange.changeEx;
|
||||
source.obj._send({
|
||||
id: source.obj._id,
|
||||
siblings: source.obj._siblings,
|
||||
value: source.obj.value,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const value = (source.obj.value = this.mergeChange(event));
|
||||
let selStart, selEnd;
|
||||
if (
|
||||
|
|
|
@ -242,6 +242,11 @@ class Field extends PDFObject {
|
|||
}
|
||||
|
||||
set value(value) {
|
||||
if (this._isChoice) {
|
||||
this._setChoiceValue(value);
|
||||
return;
|
||||
}
|
||||
|
||||
if (value === "") {
|
||||
this._value = "";
|
||||
} else if (typeof value === "string") {
|
||||
|
@ -260,23 +265,37 @@ class Field extends PDFObject {
|
|||
} else {
|
||||
this._value = value;
|
||||
}
|
||||
if (this._isChoice) {
|
||||
if (this.multipleSelection) {
|
||||
const values = new Set(value);
|
||||
if (Array.isArray(this._currentValueIndices)) {
|
||||
this._currentValueIndices.length = 0;
|
||||
} else {
|
||||
this._currentValueIndices = [];
|
||||
}
|
||||
this._items.forEach(({ displayValue }, i) => {
|
||||
if (values.has(displayValue)) {
|
||||
this._currentValueIndices.push(i);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
_setChoiceValue(value) {
|
||||
if (this.multipleSelection) {
|
||||
if (!Array.isArray(value)) {
|
||||
value = [value];
|
||||
}
|
||||
const values = new Set(value);
|
||||
if (Array.isArray(this._currentValueIndices)) {
|
||||
this._currentValueIndices.length = 0;
|
||||
this._value.length = 0;
|
||||
} else {
|
||||
this._currentValueIndices = this._items.findIndex(
|
||||
({ displayValue }) => value === displayValue
|
||||
);
|
||||
this._currentValueIndices = [];
|
||||
this._value = [];
|
||||
}
|
||||
this._items.forEach((item, i) => {
|
||||
if (values.has(item.exportValue)) {
|
||||
this._currentValueIndices.push(i);
|
||||
this._value.push(item.exportValue);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if (Array.isArray(value)) {
|
||||
value = value[0];
|
||||
}
|
||||
const index = this._items.findIndex(
|
||||
({ exportValue }) => value === exportValue
|
||||
);
|
||||
if (index !== -1) {
|
||||
this._currentValueIndices = index;
|
||||
this._value = this._items[index].exportValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue