Merge pull request #12108 from calixteman/radio

Add support for radios printing
This commit is contained in:
Tim van der Meij 2020-08-02 14:47:46 +02:00 committed by GitHub
commit 5a66c56eca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 202 additions and 62 deletions

View file

@ -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;
}