Content controls

Lock template fields

Keep a content control, its contents, or both from being changed during normal DOCX editing.

Content-control locks use the same two choices as Word. Protect the field wrapper when it must remain in the template, and protect its contents when people should not change the value.

Try both locks

Expand the editor, toggle either lock, then click the client address and type. Use Delete field to test whether the control itself can be removed.

Lock a template fieldOpening template...
Field protectionclient.address

Set the lock mode

Find the field by tag and apply the matching DOCX lock:

import type { LockMode } from '@superdoc/document-api';
import type { BrowserDocumentApi } from 'superdoc/ui';

export async function setTemplateFieldLock(doc: BrowserDocumentApi, tag: string, lockMode: LockMode) {
  const { items } = await doc.contentControls.selectByTag({ tag });

  if (items.length !== 1) {
    throw new Error(`Expected one content control tagged "${tag}", found ${items.length}.`);
  }

  return doc.contentControls.setLockMode({
    target: items[0].target,
    lockMode,
  });
}
Content control cannot be deletedContents cannot be editedlockMode
OffOffunlocked
OnOffsdtLocked
OffOncontentLocked
OnOnsdtContentLocked

Set a content lock after filling the field. contentLocked and sdtContentLocked reject text changes inside the control.

Keep authorization separate

Locks travel with the DOCX and constrain normal editing in SuperDoc and Word. They do not authenticate users or decide who may access or save the file. Enforce those permissions in a trusted backend. See Secure your integration.

Use the contentControls.setLockMode() reference for the complete operation contract.

On this page