---
title: "Signers and groups"
description: "Let several people fill in and sign one form, each only their own fields, by putting fields in groups and giving each signer the permissions for theirs."
source: "https://www.embedpdf.com/docs/engine/forms/groups"
---

# Signers and groups

A contract has the buyer's part and the seller's part. The buyer fills in and signs the buyer's
fields, the seller the seller's, and once the buyer has signed, nobody changes what the buyer
filled in. Groups do this: each field belongs to a group, and each user's permissions say which
groups they fill in and sign.

```ts
const { fields } = await doc.forms.list();
fields.map((field) => [field.name, field.groupId]);
// [['buyer.name', 'buyer'], ['buyer.signature', 'buyer'], ['seller.name', 'seller'], …]
```

## Put fields in groups

A field's group is its `groupId`. Give it when you create the field, or change it later:

```ts
await doc.forms.create({
  kind: 'text',
  name: 'buyer.name',
  groupId: 'buyer',
  widgets: [{ page, rect: { x: 72, y: 120, width: 200, height: 24 } }],
});
await doc.forms.update(field.ref, { groupId: 'seller' });
```

A field you create without a `groupId` is in no group, whatever your own group is
(`identity.groupId`): a field is somebody's once you say whose. `groupId: null` in the draft
means the same as leaving it out.

Putting a field in your own group takes no permission of its own. Putting it in another group
takes `fields:set-group` for that group, so a designer who prepares the contract gets one for
each party:

```ts
const designer = [
  'doc.open',
  'doc.render',
  'doc.forms.modify',
  'fields:set-group:group=buyer',
  'fields:set-group:group=seller',
];
```

`null` takes a field out of its group:

```ts
await doc.forms.update(field.ref, { groupId: null });
```

That takes `doc.forms.modify` and no `fields:set-group` permission: whoever designs the form may
take a field out of any group, as they may delete it. A field in no group can only be filled in
by a user who may fill in every field.

The group is a setting of the field: it's saved in the PDF (in the field's `/EMBD_Metadata`),
other PDF apps ignore it, and a form [export](https://www.embedpdf.com/docs/engine/forms/import-export.md) carries it.

## Fields anyone fills in

Some fields belong to no one signer: a reference number whoever signs first knows, a delivery
date either party may settle. Mark such a field `forAnyone`:

```ts
await doc.forms.create({
  kind: 'text',
  name: 'delivery.date',
  forAnyone: true,
  widgets: [{ page, rect: { x: 72, y: 200, width: 120, height: 24 } }],
});
field.forAnyone; // true
```

So a field is filled in by one of three:

| The field                    | Who fills it in                                                    |
| :--------------------------- | :----------------------------------------------------------------- |
| In a group (`groupId`)       | The users who may fill in that group's fields                      |
| `forAnyone: true`            | Every user who may fill in some field: each signer, and the sender |
| In no group, not `forAnyone` | The users who may fill in every field: the sender                  |

A field in a group can't also be `forAnyone`, and neither can a signature field: both fail with
`InvalidArg`. To move a field between a group and `forAnyone`, name both in one update:

```ts
await doc.forms.update(field.ref, { groupId: null, forAnyone: true });
await doc.forms.update(field.ref, { groupId: 'buyer', forAnyone: false });
```

Marking a field `forAnyone` lets every group's signers fill it in, so it takes the permission to put
fields in every group, `fields:set-group:all`, beside `doc.forms.modify`. `forAnyone: false` takes
`doc.forms.modify` alone, as taking a field out of its group does.

Like the group, `forAnyone` is saved in the field's `/EMBD_Metadata`, other PDF apps ignore it, and
a form export carries it. Signing [locks](#signing) a `forAnyone` field once it holds a value.

## Give each signer their group

Each signer gets the permissions to fill in and sign their own group's fields:

```ts
const buyer = ['doc.open', 'doc.render', 'fields:fill:group=buyer', 'fields:sign:group=buyer'];
const seller = ['doc.open', 'doc.render', 'fields:*:group=seller'];
```

```ts
const doc = await engine.open(
  { kind: 'bytes', bytes },
  { scope: buyer, identity: { userId: 'u_381', displayName: 'Dana Smith' } },
);
```

Every user who may read the form sees every field and every value: groups decide who changes a
field, not who sees it. When one signer must not see another's answers, give each their own
document.

Leave `doc.forms.modify` and `pdf.permissions` out of a signer's permissions. Designing the form
can delete and recreate any field, and `pdf.permissions` gives what the PDF file allows to
everyone, which can include designing it.

## Filling in

A signer fills in their fields as anyone does. A field of another group fails with `Forbidden`,
naming the permission it would take:

```ts
await doc.forms.setValue(buyerName.ref, { value: 'Dana Smith' });
await doc.forms.setValue(sellerName.ref, { value: 'x' });
// Forbidden: details.required is 'fields:fill:group=seller'
await doc.forms.setValue(deliveryDate.ref, { value: '2026-12-01' }); // a `forAnyone` field: allowed
```

A field a script calculates, such as a total, may be in another group or in none. Write it in
the same change as the field it's calculated from, and it's allowed:

```ts
await doc.apply({
  ops: [
    { type: 'forms.setValue', field: price.ref, value: { value: '1200' } },
    { type: 'forms.setValue', field: total.ref, value: { value: '1452' } },
  ],
});
```

A reset that names a field the signer may not fill in is refused, and so is a reset of the whole
form, so pass their own: `doc.forms.reset(myFields)`. A [values import](https://www.embedpdf.com/docs/engine/forms/import-export.md#fill-in-from-a-bundle)
leaves out the other fields, with the reason `fill-not-allowed`.

## Signing

A signer signs their own signature field, and only theirs:

```ts
const prepared = await doc.signatures.prepare({ field: buyerSignature.ref });
```

When you name no `lock`, signing locks what the signer has seen:

- **The rest of the group,** when the signature field is in one: every field in it as it is when
  the buyer signs, except its signature fields.
- **Every `forAnyone` field that holds a value,** whoever filled it in: this signer, an earlier one,
  or the sender before sending. This holds for a signature field in no group too.

After that, writing one of them fails with `ProtectedDocument` for everyone, in this engine and in
other PDF apps. A `forAnyone` field still empty when the buyer signs stays open: the seller may fill
it in, and it locks when the seller signs. Name a
[`lock`](https://www.embedpdf.com/docs/engine/forms/signatures.md#lock-fields) to choose the fields yourself; then nothing is
added to it. Nothing is added either when the PDF already locks the signature field itself (its own
`/Lock`, which another tool may have set): the signing locks what that lock says.

The engine doesn't order the signers. Give the seller their permissions when the buyer is done.

Validation data, and the document timestamp that follows it, belong to the document and not to a
group, so they take `doc.sign`. A signer who should leave a file that can be checked for years gets
it beside their group:

```ts
const buyer = [
  'doc.open',
  'doc.render',
  'doc.sign',
  'fields:fill:group=buyer',
  'fields:sign:group=buyer',
];
```

It lets them sign nothing more. While the list has a `fields:sign` permission, that alone decides
which fields they sign: not the seller's, and not a field in no group.

## Build the interface from it

Ask before you show a control:

```ts
doc.security.allowsField('fill', field); // may the user fill this field in?
doc.security.allowsField('sign', field); // …sign this signature field?
doc.security.allowsField('set-group', { groupId: 'buyer' }); // …put fields in the buyer's group?
```

To show whose fields are the user's before they pick one, ask for every field at once:

```ts
const rights = doc.security.fieldRights();
rights.fill; // { all: true }, or { all: false, groups: ['buyer'] }
rights.sign; // the same, for signature fields
rights.setGroup; // the groups the user may put a field in
```

`{ all: true }` is every field. Otherwise only the fields in `groups` are the user's; a field in
no group isn't, and an empty list is no field at all. A `forAnyone` field is the user's to fill in
unless `fill` is that empty list. A user may mark fields `forAnyone` when `setGroup` is
`{ all: true }`.

The engine checks every write the same way, so these answers never disagree with a call. See
[Permissions](https://www.embedpdf.com/docs/engine/concepts/permissions.md#form-fields).
