From 3736000aeef000390617ba2c3be5b9dd3488b131 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 28 Jul 2026 19:04:17 +0200 Subject: [PATCH] Shorten the `AnnotationElement.prototype._getElementsByName` method a tiny bit --- src/display/annotation_layer.js | 35 +++++++++++++++------------------ 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/src/display/annotation_layer.js b/src/display/annotation_layer.js index 490262ebd..80642ee5a 100644 --- a/src/display/annotation_layer.js +++ b/src/display/annotation_layer.js @@ -803,27 +803,24 @@ class AnnotationElement { const fields = []; if (this._fieldObjects) { - const fieldObj = this._fieldObjects[name]; - if (fieldObj) { - for (const { page, id, exportValues } of fieldObj) { - if (page === -1) { - continue; - } - if (id === skipId) { - continue; - } - const exportValue = - typeof exportValues === "string" ? exportValues : null; + const fieldObj = this._fieldObjects[name] || []; - const domElement = document.querySelector( - `[data-element-id="${id}"]` - ); - if (domElement && !GetElementsByNameSet.has(domElement)) { - warn(`_getElementsByName - element not allowed: ${id}`); - continue; - } - fields.push({ id, exportValue, domElement }); + for (const { page, id, exportValues } of fieldObj) { + if (page === -1) { + continue; } + if (id === skipId) { + continue; + } + const exportValue = + typeof exportValues === "string" ? exportValues : null; + + const domElement = document.querySelector(`[data-element-id="${id}"]`); + if (domElement && !GetElementsByNameSet.has(domElement)) { + warn(`_getElementsByName - element not allowed: ${id}`); + continue; + } + fields.push({ id, exportValue, domElement }); } return fields; }