0

I have an XForm document in LibreOffice Writer 5. The form contains various text boxes and date fields. What I want is to create a Javascript macro that will be assigned to one text box and perform some actions whenever the user changes the input of this field. So far I have written the following

var oDoc = UnoRuntime.queryInterface(XModel, XSCRIPTCONTEXT.getInvocationContext());
if (!oDoc) {
    oDoc = XSCRIPTCONTEXT.getDocument();
}
var xFieldsSupplier = UnoRuntime.queryInterface(XFormsSupplier, oDoc);
var xForm = xFieldsSupplier.getXForms();

but xForm is null. Does anyone know how I can get the XForm fields? Is there something wrong with the above code?

dchar
  • 1,665
  • 2
  • 19
  • 28

1 Answers1

0

The code looks fine. It seems to be an issue with Javascript, because I tested similar code using other languages and it worked. In Python this printed the form name:

xforms = oDoc.getXForms()
formName = xforms.getElementNames()[0]
xTextRange = xText.getEnd()
xTextRange.setString(formName)
xform = xforms.getByName(formName)

The same thing worked in Java:

XFormsSupplier xFormsSupplier = UnoRuntime.queryInterface(
    XFormsSupplier.class, xComponent);
XNameContainer xforms = xFormsSupplier.getXForms();
String formName = xforms.getElementNames()[0];
xTextRange = xText.getEnd();
xTextRange.setString(formName);
Object aForm = xforms.getByName(formName);

This introduction indicates that Javascript support for UNO is still in its infancy.

Note that XFormsSupplier is not published, which presumably means the interface is subject to change or instability.

Jim K
  • 12,824
  • 2
  • 22
  • 51