I am using DOCX.js to generate a word document which has an address section. I am trying to create a paragraph that always shows the first paragraph with the text “Address” and then insert a paragraph below to build the address. I am using a conditional statement to enter a new paragraph if a PO Box is supplied or skip if no PO Box is supplied. Here is the code:
//...Other Paragraphs
new TableRow({
children: [
new TableCell({
children: [
new Paragraph({
spacing: {
before: 200,
},
children: [
new TextRun({
text: "Address",
size: 24,
color: "848484",
}),
],
}),
element["BO/RLE/DBO/CT PO Box"] &&
new Paragraph({
children: [
new TextRun({
text: element["BO/RLE/DBO/CT PO Box"],
size: 24,
color: "000000",
}),
],
}),
],
}),
],
}),
//...Other Paragraphs
The problem I’m having is that the Paragraph with the “Address” TextRun is also acting conditionally, even though it’s outside of the conditional statement below it (i.e. If there is no PO Box, the “Address” paragraph also doesn’t appear.)
Is there anything wrong with my code?
TIA