[JS] Take into account all the required fields for some computations

- Fix Field::getArray in order to collect only the fields which have a value;
- Fix AFSimple_Calculate:
  * allow to have a string with a list of field names as argument;
  * since a field can be non-terminal, use Field::getArray to collect
    the field under it and then apply the calculation on all the descendants.
This commit is contained in:
Calixte Denizet 2022-10-13 15:48:01 +02:00
parent c6cc7c6e6a
commit e756bb69e4
4 changed files with 154 additions and 10 deletions

View file

@ -889,6 +889,24 @@ class Doc extends PDFObject {
return children;
}
_getTerminalChildren(fieldName) {
// Get all the descendants which have a value.
const children = [];
const len = fieldName.length;
for (const [name, field] of this._fields.entries()) {
if (name.startsWith(fieldName)) {
const finalPart = name.slice(len);
if (
field.obj._hasValue &&
(finalPart === "" || finalPart.startsWith("."))
) {
children.push(field.wrapped);
}
}
}
return children;
}
getIcon() {
/* Not implemented */
}