0

I'm using docxtemplater to create a word document based on JSON values (using surveyJS). In case some questions are not answered, the variable shows "undefined" in the final document.

How can I make sure that any "undefined" output is highlighted? I found some answers on how to use nullGetter to replace "undefined" with a custom string but nothing on text background.

The JSON looks something like this:

{
    "nameIndividual": "John Smith",
    "mgmt": "Management Name",
    "mgmtName": "Tim Test",
    "address": "854 Test Avenue, Example City",
    "email": "test@management.com",
    "socialMediaOptions": [
        "Twitter",
        "YouTube",
        "Instagram",
        "Facebook"
    ]
}

Is there a way to do this in the word template itself without having to write {#nameIndividual == undefined}Undefined{/} for every single variable...

If not, how can this be done with Javascript?

Any help is highly appreciated!

Thanks!

Jenny_cgn21
  • 33
  • 1
  • 6

1 Answers1

1

You would have to use the docxtemplater HTML module for this. It supports setting a background-color style to html elements. Look here:

https://docxtemplater.com/modules/html/

Instead of undefined you could add <span style="background-color: red">Undefined<span> for the missing value.

Mario Varchmin
  • 3,704
  • 4
  • 18
  • 33