6

I'm using ruby/nokogiri to parse a word form and fill the fields. I've already managed to fill the text fields but I'm having difficulties to check a checkbox. I've looked on the document.xml and didn't notice any different tags when the checkbox is marked or not

Kara
  • 6,115
  • 16
  • 50
  • 57
Adriano Bacha
  • 1,114
  • 2
  • 13
  • 22

2 Answers2

3

I've found the solution when a checkbox is checked, there is a tag: <checked /> and when it isn't checked it is: <checked val='0' />

checksum
  • 6,415
  • 4
  • 36
  • 34
Adriano Bacha
  • 1,114
  • 2
  • 13
  • 22
  • Thanks. This works! I hope that the team that made this up is mostly preoccupied with designing Microsoft Word internals. – Gijs Jun 13 '16 at 13:24
3

You need your XML to look like:

<w:ffData>
  <w:checkBox>
    <w:size w:val="20" />
    <w:checked w:val="true" />
  </w:checkBox>
</w:ffData>

Observe that w:checked has the parent w:checkBox. Documentation on CheckBox class

Alternatively you can set the default state.

Unchecked: <w:default w:val="0"/>

Checked: <w:default w:val="1"/>

 <w:ffData>
   <w:checkBox>
     <w:default w:val="1" />
   </w:checkBox>
 </w:ffData>
Valentin Despa
  • 40,712
  • 18
  • 80
  • 106