mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Outline fields which are required (bug 1724918)
- it aims to fix https://bugzilla.mozilla.org/show_bug.cgi?id=1724918; - it applies for both Acroform and XFA.
This commit is contained in:
parent
c25429be44
commit
2dd0c861bf
8 changed files with 88 additions and 7 deletions
|
@ -1363,6 +1363,7 @@ class WidgetAnnotation extends Annotation {
|
|||
}
|
||||
|
||||
data.readOnly = this.hasFieldFlag(AnnotationFieldFlag.READONLY);
|
||||
data.required = this.hasFieldFlag(AnnotationFieldFlag.REQUIRED);
|
||||
data.hidden = this._hasFlag(data.annotationFlags, AnnotationFlag.HIDDEN);
|
||||
}
|
||||
|
||||
|
|
|
@ -204,6 +204,10 @@ function* getContainedChildren(node) {
|
|||
}
|
||||
}
|
||||
|
||||
function isRequired(node) {
|
||||
return node.validate && node.validate.nullTest === "error";
|
||||
}
|
||||
|
||||
function setTabIndex(node) {
|
||||
while (node) {
|
||||
if (!node.traversal) {
|
||||
|
@ -1368,6 +1372,7 @@ class CheckButton extends XFAObject {
|
|||
xfaOn: exportedValue.on,
|
||||
xfaOff: exportedValue.off,
|
||||
"aria-label": ariaLabel(field),
|
||||
"aria-required": false,
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -1375,6 +1380,11 @@ class CheckButton extends XFAObject {
|
|||
input.attributes.name = groupId;
|
||||
}
|
||||
|
||||
if (isRequired(field)) {
|
||||
input.attributes["aria-required"] = true;
|
||||
input.attributes.required = true;
|
||||
}
|
||||
|
||||
return HTMLResult.success({
|
||||
name: "label",
|
||||
attributes: {
|
||||
|
@ -1465,8 +1475,14 @@ class ChoiceList extends XFAObject {
|
|||
dataId: (field[$data] && field[$data][$uid]) || field[$uid],
|
||||
style,
|
||||
"aria-label": ariaLabel(field),
|
||||
"aria-required": false,
|
||||
};
|
||||
|
||||
if (isRequired(field)) {
|
||||
selectAttributes["aria-required"] = true;
|
||||
selectAttributes.required = true;
|
||||
}
|
||||
|
||||
if (this.open === "multiSelect") {
|
||||
selectAttributes.multiple = true;
|
||||
}
|
||||
|
@ -1704,9 +1720,15 @@ class DateTimeEdit extends XFAObject {
|
|||
class: ["xfaTextfield"],
|
||||
style,
|
||||
"aria-label": ariaLabel(field),
|
||||
"aria-required": false,
|
||||
},
|
||||
};
|
||||
|
||||
if (isRequired(field)) {
|
||||
html.attributes["aria-required"] = true;
|
||||
html.attributes.required = true;
|
||||
}
|
||||
|
||||
return HTMLResult.success({
|
||||
name: "label",
|
||||
attributes: {
|
||||
|
@ -3859,9 +3881,15 @@ class NumericEdit extends XFAObject {
|
|||
class: ["xfaTextfield"],
|
||||
style,
|
||||
"aria-label": ariaLabel(field),
|
||||
"aria-required": false,
|
||||
},
|
||||
};
|
||||
|
||||
if (isRequired(field)) {
|
||||
html.attributes["aria-required"] = true;
|
||||
html.attributes.required = true;
|
||||
}
|
||||
|
||||
return HTMLResult.success({
|
||||
name: "label",
|
||||
attributes: {
|
||||
|
@ -5833,6 +5861,7 @@ class TextEdit extends XFAObject {
|
|||
class: ["xfaTextfield"],
|
||||
style,
|
||||
"aria-label": ariaLabel(field),
|
||||
"aria-required": false,
|
||||
},
|
||||
};
|
||||
} else {
|
||||
|
@ -5845,10 +5874,16 @@ class TextEdit extends XFAObject {
|
|||
class: ["xfaTextfield"],
|
||||
style,
|
||||
"aria-label": ariaLabel(field),
|
||||
"aria-required": false,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
if (isRequired(field)) {
|
||||
html.attributes["aria-required"] = true;
|
||||
html.attributes.required = true;
|
||||
}
|
||||
|
||||
return HTMLResult.success({
|
||||
name: "label",
|
||||
attributes: {
|
||||
|
|
|
@ -343,11 +343,7 @@ class AnnotationElement {
|
|||
}
|
||||
},
|
||||
required: event => {
|
||||
if (event.detail.required) {
|
||||
event.target.setAttribute("required", "");
|
||||
} else {
|
||||
event.target.removeAttribute("required");
|
||||
}
|
||||
this._setRequired(event.target, event.detail.required);
|
||||
},
|
||||
bgColor: event => {
|
||||
setColor("bgColor", "backgroundColor", event);
|
||||
|
@ -944,6 +940,15 @@ class WidgetAnnotationElement extends AnnotationElement {
|
|||
style.textAlign = TEXT_ALIGNMENT[this.data.textAlignment];
|
||||
}
|
||||
}
|
||||
|
||||
_setRequired(element, isRequired) {
|
||||
if (isRequired) {
|
||||
element.setAttribute("required", true);
|
||||
} else {
|
||||
element.removeAttribute("required");
|
||||
}
|
||||
element.setAttribute("aria-required", isRequired);
|
||||
}
|
||||
}
|
||||
|
||||
class TextWidgetAnnotationElement extends WidgetAnnotationElement {
|
||||
|
@ -1010,6 +1015,8 @@ class TextWidgetAnnotationElement extends WidgetAnnotationElement {
|
|||
elementData.userValue = textContent;
|
||||
element.setAttribute("id", id);
|
||||
|
||||
this._setRequired(element, this.data.required);
|
||||
|
||||
element.addEventListener("input", event => {
|
||||
storage.setValue(id, { value: event.target.value });
|
||||
this.setPropertyOnSiblings(
|
||||
|
@ -1255,6 +1262,7 @@ class CheckboxWidgetAnnotationElement extends WidgetAnnotationElement {
|
|||
const element = document.createElement("input");
|
||||
GetElementsByNameSet.add(element);
|
||||
element.disabled = data.readOnly;
|
||||
this._setRequired(element, this.data.required);
|
||||
element.type = "checkbox";
|
||||
element.name = data.fieldName;
|
||||
if (value) {
|
||||
|
@ -1338,6 +1346,7 @@ class RadioButtonWidgetAnnotationElement extends WidgetAnnotationElement {
|
|||
const element = document.createElement("input");
|
||||
GetElementsByNameSet.add(element);
|
||||
element.disabled = data.readOnly;
|
||||
this._setRequired(element, this.data.required);
|
||||
element.type = "radio";
|
||||
element.name = data.fieldName;
|
||||
if (value) {
|
||||
|
@ -1447,6 +1456,7 @@ class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement {
|
|||
const selectElement = document.createElement("select");
|
||||
GetElementsByNameSet.add(selectElement);
|
||||
selectElement.disabled = this.data.readOnly;
|
||||
this._setRequired(selectElement, this.data.required);
|
||||
selectElement.name = this.data.fieldName;
|
||||
selectElement.setAttribute("id", id);
|
||||
selectElement.tabIndex = DEFAULT_TAB_INDEX;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue