mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Merge pull request #12108 from calixteman/radio
Add support for radios printing
This commit is contained in:
commit
5a66c56eca
3 changed files with 202 additions and 62 deletions
|
@ -1078,16 +1078,19 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
|
|||
if (!isDict(appearanceStates)) {
|
||||
return;
|
||||
}
|
||||
const normalAppearanceState = appearanceStates.get("N");
|
||||
if (!isDict(normalAppearanceState)) {
|
||||
const normalAppearance = appearanceStates.get("N");
|
||||
if (!isDict(normalAppearance)) {
|
||||
return;
|
||||
}
|
||||
for (const key of normalAppearanceState.getKeys()) {
|
||||
for (const key of normalAppearance.getKeys()) {
|
||||
if (key !== "Off") {
|
||||
this.data.buttonValue = key;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
this.checkedAppearance = normalAppearance.get(this.data.buttonValue);
|
||||
this.uncheckedAppearance = normalAppearance.get("Off") || null;
|
||||
}
|
||||
|
||||
_processPushButton(params) {
|
||||
|
|
|
@ -586,15 +586,35 @@ class RadioButtonWidgetAnnotationElement extends WidgetAnnotationElement {
|
|||
*/
|
||||
render() {
|
||||
this.container.className = "buttonWidgetAnnotation radioButton";
|
||||
const storage = this.annotationStorage;
|
||||
const data = this.data;
|
||||
const id = data.id;
|
||||
const value = storage.getOrCreateValue(
|
||||
id,
|
||||
data.fieldValue === data.buttonValue
|
||||
);
|
||||
|
||||
const element = document.createElement("input");
|
||||
element.disabled = this.data.readOnly;
|
||||
element.disabled = data.readOnly;
|
||||
element.type = "radio";
|
||||
element.name = this.data.fieldName;
|
||||
if (this.data.fieldValue === this.data.buttonValue) {
|
||||
element.name = data.fieldName;
|
||||
if (value) {
|
||||
element.setAttribute("checked", true);
|
||||
}
|
||||
|
||||
element.addEventListener("change", function (event) {
|
||||
const name = event.target.name;
|
||||
for (const radio of document.getElementsByName(name)) {
|
||||
if (radio !== event.target) {
|
||||
storage.setValue(
|
||||
radio.parentNode.getAttribute("data-annotation-id"),
|
||||
false
|
||||
);
|
||||
}
|
||||
}
|
||||
storage.setValue(id, event.target.checked);
|
||||
});
|
||||
|
||||
this.container.appendChild(element);
|
||||
return this.container;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue