1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

Add support for radios printing

This commit is contained in:
Calixte Denizet 2020-07-22 17:29:35 +02:00
parent eb4d6a0652
commit 538017f7a7
3 changed files with 150 additions and 40 deletions

View file

@ -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) {

View file

@ -584,15 +584,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;
}