From 112645ea3dd4bcb13e08579f9971918bcd7e0ed7 Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Sun, 6 Jun 2021 17:59:01 +0200 Subject: [PATCH] XFA - Don't bind a form node with an empty value when the data node doesn't exist --- src/core/xfa/bind.js | 4 +++ test/unit/xfa_parser_spec.js | 60 ++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/src/core/xfa/bind.js b/src/core/xfa/bind.js index e6f227ebe66dc..e5b5a614b4141 100644 --- a/src/core/xfa/bind.js +++ b/src/core/xfa/bind.js @@ -577,6 +577,10 @@ class Binder { // what we've in template. match = new XmlObject(dataNode[$namespaceId], child.name); dataNode[$appendChild](match); + + // Don't bind the value in newly created node because it's empty. + this._bindElement(child, match); + continue; } match = [match]; } diff --git a/test/unit/xfa_parser_spec.js b/test/unit/xfa_parser_spec.js index 6ff3e5b2221bc..d080a870c9606 100644 --- a/test/unit/xfa_parser_spec.js +++ b/test/unit/xfa_parser_spec.js @@ -749,6 +749,66 @@ describe("XFAParser", function () { ).toBe("xyz"); }); + it("should make a basic binding and create a non-existing node", function () { + const xml = ` + + + + + + + + + + + `; + const root = new XFAParser().parse(xml); + const binder = new Binder(root); + const form = binder.bind(); + const data = binder.getData(); + + expect( + searchNode(form, form, "A.B.D.value.text")[0][$dump]().$content + ).toBe("foobar"); + + const expected = { + $name: "A", + attributes: {}, + children: [ + { + $name: "B", + attributes: {}, + children: [ + { + $name: "C", + attributes: {}, + children: [], + }, + { + $name: "D", + attributes: {}, + children: [], + }, + ], + }, + ], + }; + + expect(searchNode(data, data, "A")[0][$dump]()).toEqual(expected); + }); + it("should make another basic binding", function () { const xml = `