Shorten the AnnotationElement.prototype._getElementsByName method a tiny bit

This commit is contained in:
Jonas Jenwald 2026-07-28 19:04:17 +02:00
parent 8d1afad39b
commit 3736000aee

View File

@ -803,8 +803,8 @@ class AnnotationElement {
const fields = []; const fields = [];
if (this._fieldObjects) { if (this._fieldObjects) {
const fieldObj = this._fieldObjects[name]; const fieldObj = this._fieldObjects[name] || [];
if (fieldObj) {
for (const { page, id, exportValues } of fieldObj) { for (const { page, id, exportValues } of fieldObj) {
if (page === -1) { if (page === -1) {
continue; continue;
@ -815,16 +815,13 @@ class AnnotationElement {
const exportValue = const exportValue =
typeof exportValues === "string" ? exportValues : null; typeof exportValues === "string" ? exportValues : null;
const domElement = document.querySelector( const domElement = document.querySelector(`[data-element-id="${id}"]`);
`[data-element-id="${id}"]`
);
if (domElement && !GetElementsByNameSet.has(domElement)) { if (domElement && !GetElementsByNameSet.has(domElement)) {
warn(`_getElementsByName - element not allowed: ${id}`); warn(`_getElementsByName - element not allowed: ${id}`);
continue; continue;
} }
fields.push({ id, exportValue, domElement }); fields.push({ id, exportValue, domElement });
} }
}
return fields; return fields;
} }
// Fallback to a regular DOM lookup, to ensure that the standalone // Fallback to a regular DOM lookup, to ensure that the standalone