docx-templates icon indicating copy to clipboard operation
docx-templates copied to clipboard

How can i insert checkbox into template correctly?

Open ulknight opened this issue 5 years ago • 3 comments

I need insert active checkbox if "Some var" is true else insert empty checkbox.

I try this ALIES, IF/END-IF, VAR?"value1":"value2", but every time active checkbox is appears, even need to be empty checkbox only. I have attached docx file with examples of code. testTemplate.docx

I think it is issue this "sym" value of active checkbox, because of: empty checkbox code is:

                        <w:r w:rsidR="00722482">
                            <w:rPr>
                                <w:rFonts w:ascii="MS Gothic" w:eastAsia="MS Gothic" w:hAnsi="MS Gothic"
                                          w:cs="Times New Roman" w:hint="eastAsia"/>
                                <w:sz w:val="20"/>
                                <w:szCs w:val="20"/>
                            </w:rPr>
                            <w:t>☐</w:t>
                        </w:r> 

but active ckecbox is:

                        <w:r w:rsidR="00722482">
                            <w:rPr>
                                <w:rFonts w:ascii="Times New Roman" w:eastAsia="Times New Roman"
                                          w:hAnsi="Times New Roman" w:cs="Times New Roman"/>
                                <w:sz w:val="20"/>
                                <w:szCs w:val="20"/>
                            </w:rPr>
                            <w:sym w:font="Wingdings" w:char="F0FE"/>
                        </w:r>

And in best part I need insert this part of code (then checkbox is dinamical):

                        <w:sdt>
                            <w:sdtPr>
                                <w:rPr>
                                    <w:rFonts w:ascii="Times New Roman" w:eastAsia="Times New Roman"
                                              w:hAnsi="Times New Roman" w:cs="Times New Roman"/>
                                    <w:sz w:val="20"/>
                                    <w:szCs w:val="20"/>
                                </w:rPr>
                                <w:id w:val="-610430821"/>
                                <w14:checkbox>
                                    <w14:checked w14:val="1"/>
                                    <w14:checkedState w14:val="00FE" w14:font="Wingdings"/>
                                    <w14:uncheckedState w14:val="2610" w14:font="MS Gothic"/>
                                </w14:checkbox>
                            </w:sdtPr>
                            <w:sdtEndPr/>
                            <w:sdtContent>
                                <w:r w:rsidR="00DC30A1">
                                    <w:rPr>
                                        <w:rFonts w:ascii="Times New Roman" w:eastAsia="Times New Roman"
                                                  w:hAnsi="Times New Roman" w:cs="Times New Roman"/>
                                        <w:sz w:val="20"/>
                                        <w:szCs w:val="20"/>
                                    </w:rPr>
                                    <w:sym w:font="Wingdings" w:char="F0FE"/>
                                </w:r>
                            </w:sdtContent>
                        </w:sdt>

ulknight avatar Feb 17 '20 14:02 ulknight

Hi @ulknight, how did you manage to insert a dynamic checkbox?

lukakiro avatar May 12 '22 14:05 lukakiro

additional js function for dynamic checkbox

(field, value) => {
    if (value !== null && value !== undefined) {
        return field == value ? '✓' : '☐'
    } else {
        return field ? '✓' : '☐'
    }
} 

khtodod avatar Aug 18 '22 07:08 khtodod

Thanks for your answer @Arthemis97 ! Let me know if this works for you, @lukakiro @ulknight . I may add it to the docs if it is a solid solution.

jjhbw avatar Aug 18 '22 09:08 jjhbw