XFA form tree creation and editing

TXFAWidgetRuntime supports transactional JavaScript creation, cloning and editing of the live form tree through xfa.form and node collections

The live form tree has independent native identities and can be saved as an XDP form packet without modifying the authored template

Creating and inserting a field

var row = xfa.resolveNode("row[1]");
var field = xfa.form.createNode("field", "additional");
row.nodes.append(field);
field.w = "160pt";
field.h = "24pt";
field.ui.getElement("textEdit");
field.font.typeface = "DejaVu Sans";
field.rawValue = "Additional value";

createNode(className, name, namespaceURI) returns a detached node, with an empty name and the model namespace used when the optional arguments are omitted

The accepted classes include field, subform, draw, area, exclGroup and the property classes recognised by the runtime property schema

Creating a node does not insert it into the form or create a visible widget until it is attached with the required UI and value properties

Collection operations and cloning

OperationBehaviour
parent.nodes.append(node)Moves a detached or attached node to the end of the parent's live child collection
parent.nodes.insert(node, before)Moves the node immediately before an existing child of the same parent
parent.nodes.remove(node)Detaches a child whilst retaining its script identity for later reuse
node.clone(true)Returns a detached deep clone with separate native and script identities
node.clone(false)Returns a detached shallow clone without child nodes or a copied field value

Collection order, parent, property lookup and supported SOM resolution reflect successful edits immediately inside the event

References retained by script objects continue to address their own nodes after a committed edit or an event rollback, including detached deep and shallow clones

A cycle, a reference child from a different parent or a data-model node passed to a form operation raises an exception before that invalid operation changes the tree

The form model root can contain newly created subforms and fields, but the model root itself cannot be moved or cloned

Repeated scopes and initial instances

Actual form instances retain separate identities even when their authored names are equal, their data contexts differ or no datasets packet exists

An empty merge uses the explicit occur.initial count, or occur.min when initial is absent, and an absent max defaults to min

For an empty merge, an initial count outside the minimum and maximum is permitted, including zero initial copies

Nested and unnamed subforms retain their own occurrence paths, and materialising these instances does not synthesise a datasets packet

These occurrence rules follow XML Forms Architecture 3.3, printed pages 339–345

Commit, rollback and output

A successful event applies its structural journal, rebuilds native widgets and makes the edited form available to SaveToBytes and automatic native PDF creation

An uncaught script exception, native commit failure or exceeded event budget restores the original document, widget identities and retained script state, so a later event can retry

The existing operation, node, depth, byte, widget and elapsed-time budgets also apply to structural preparation and commit

Saved form instances can be reloaded and passed to HPDFXFAWriteHeadlessPDF to create real PDF fields and appearance streams with supplied font bytes

Scope

These APIs edit the live form model and its supported property schema

General xfa.template editing, complete choice subform-set processing, the full XFA class schema and arbitrary binding selector combinations remain separate capabilities