# 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 [#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.

> **Interactive editor: Lock a template field**
>
> The service-agreement DOCX contains one text control tagged `client.address`. The demo applies the same two locking choices that Word exposes:
>
> - **Content control cannot be deleted** protects the field wrapper.
> - **Contents cannot be edited** blocks changes inside the field.
>
> Toggle either choice, then edit or delete the field. Reset restores the prepared document.


## Set the lock mode [#set-the-lock-mode]

In the [runnable Fill example](https://go.superdoc.dev/examples/content-controls?workflow=fill), 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](/editor/content-controls/fill-a-docx-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:

```ts
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](/editor/load-and-save-documents), 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 [#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](/editor/secure-integration).

Use the [`contentControls.setLockMode()` reference](/document-api/reference/content-controls/set-lock-mode/) for the
complete operation contract.
