# 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]

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

```ts
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 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.

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