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.
Set the lock mode
In the runnable Fill example, update the address, then select Lock address after filling. Export the DOCX to keep both the value and its lock. Clear the checkbox to allow edits again.
Continue with the filled template. After onReady, pass
superdoc.activeEditor.doc, the tag client.address, and a mode below to this helper. That tag identifies the single
address control used in the demo. The helper requires exactly one match; client.legalName has three occurrences.
It uses the types shipped with superdoc; no separate Document API package is needed.
Find the field by tag and apply the matching DOCX lock:
import type { BrowserDocumentApi, ContentControlInfo } from 'superdoc/ui';
export async function setTemplateFieldLock(
doc: BrowserDocumentApi,
tag: string,
lockMode: ContentControlInfo['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 deleted | Contents cannot be edited | lockMode |
|---|---|---|
| Off | Off | unlocked |
| On | Off | sdtLocked |
| Off | On | contentLocked |
| On | On | sdtContentLocked |
Set a content lock after filling the field. contentLocked and sdtContentLocked reject text changes inside the
control.
Export with your existing load and save flow, then reopen the file and try the same edit or deletion. Check the lock on the saved control, not just the state of your application's checkbox.
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.