Edit

Share via


Word.ContentControlOptions interface

Specifies the options that define which content controls are returned.

Remarks

[ API set: WordApi 1.5 ]

Examples

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/10-content-controls/insert-and-change-checkbox-content-control.yaml

// Toggles the isChecked property of the first checkbox content control found in the selection.
await Word.run(async (context) => {
  const selectedRange: Word.Range = context.document.getSelection();
  let selectedContentControl = selectedRange
    .getContentControls({
      types: [Word.ContentControlType.checkBox]
    })
    .getFirstOrNullObject();
  selectedContentControl.load("id,checkboxContentControl/isChecked");

  await context.sync();

  if (selectedContentControl.isNullObject) {
    const parentContentControl: Word.ContentControl = selectedRange.parentContentControl;
    parentContentControl.load("id,type,checkboxContentControl/isChecked");
    await context.sync();

    if (parentContentControl.isNullObject || parentContentControl.type !== Word.ContentControlType.checkBox) {
      console.warn("No checkbox content control is currently selected.");
      return;
    } else {
      selectedContentControl = parentContentControl;
    }
  }

  const isCheckedBefore = selectedContentControl.checkboxContentControl.isChecked;
  console.log("isChecked state before:", `id: ${selectedContentControl.id} ... isChecked: ${isCheckedBefore}`);
  selectedContentControl.checkboxContentControl.isChecked = !isCheckedBefore;
  selectedContentControl.load("id,checkboxContentControl/isChecked");
  await context.sync();

  console.log(
    "isChecked state after:",
    `id: ${selectedContentControl.id} ... isChecked: ${selectedContentControl.checkboxContentControl.isChecked}`
  );
});

Properties

types

An array of content control types, item must be richText, plainText, checkBox, dropDownList, comboBox, buildingBlockGallery, datePicker, repeatingSection, picture, or group.

Property Details

types

An array of content control types, item must be richText, plainText, checkBox, dropDownList, comboBox, buildingBlockGallery, datePicker, repeatingSection, picture, or group.

types: Word.ContentControlType[];

Property Value

Remarks

[ API set: WordApi 1.5 ]

Note: plainText support was added in WordApi 1.5. checkBox support was added in WordApi 1.7. dropDownList and comboBox support was added in WordApi 1.9. Support for buildingBlockGallery, datePicker, group, picture, and repeatingSection was added in WordApiDesktop 1.3.