mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
JS - reset correctly radio buttons
This commit is contained in:
parent
4b49db7c95
commit
c01ef24541
3 changed files with 16 additions and 8 deletions
|
@ -1002,7 +1002,6 @@ class RadioButtonWidgetAnnotationElement extends WidgetAnnotationElement {
|
|||
if (value) {
|
||||
element.setAttribute("checked", true);
|
||||
}
|
||||
element.setAttribute("pdfButtonValue", data.buttonValue);
|
||||
element.setAttribute("id", id);
|
||||
|
||||
element.addEventListener("change", function (event) {
|
||||
|
@ -1016,19 +1015,16 @@ class RadioButtonWidgetAnnotationElement extends WidgetAnnotationElement {
|
|||
});
|
||||
|
||||
if (this.enableScripting && this.hasJSActions) {
|
||||
const pdfButtonValue = data.buttonValue;
|
||||
element.addEventListener("updatefromsandbox", event => {
|
||||
const { detail } = event;
|
||||
const actions = {
|
||||
value() {
|
||||
const fieldValue = detail.value;
|
||||
const checked = pdfButtonValue === detail.value;
|
||||
for (const radio of document.getElementsByName(event.target.name)) {
|
||||
const radioId = radio.getAttribute("id");
|
||||
if (fieldValue === radio.getAttribute("pdfButtonValue")) {
|
||||
radio.setAttribute("checked", true);
|
||||
storage.setValue(radioId, { value: true });
|
||||
} else {
|
||||
storage.setValue(radioId, { value: false });
|
||||
}
|
||||
radio.checked = radioId === id && checked;
|
||||
storage.setValue(radioId, { value: radio.checked });
|
||||
}
|
||||
},
|
||||
focus() {
|
||||
|
|
|
@ -481,6 +481,9 @@ class RadioButtonField extends Field {
|
|||
}
|
||||
|
||||
set value(value) {
|
||||
if (value === null) {
|
||||
this._value = "";
|
||||
}
|
||||
const i = this.exportValues.indexOf(value);
|
||||
if (0 <= i && i < this._radioIds.length) {
|
||||
this._id = this._radioIds[i];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue