Search code examples
xformsxsltforms

Accessing the XForms/XSLTForms model instances with javascript


I'm trying -uncessfully- to access the instances of my model, in order to add some data via Js. I know I can do that by adding a trigger with an insert action, but I'm working with some canvas so I really need to do the same via Js.

I added a onLoad function that is triggered when the document body is already loaded. I tryed to get the instance with the "instance" action of xforms, but it is not recognized as a function.

var instanceElement = instance('application');
console.log( instanceElement);

I also tryed to get the instance with:

document.getElementById(id);

But it returned null. So, how can access the model? Thanks in advance!


Solution

  • var model = window.document.getElementById("model-id");
    var ins = model.getInstanceDocument("instance-id");
    console.log(ins.documentElement.textContent);