> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/web/forms/create-fields.md).

# Create new PDF form fields using JavaScript

Learn how to create new PDF form fields using JavaScript. Add text boxes, checkboxes, radio buttons, and more to gather user information interactively. The Apryse Web SDK streamlines secure, serverles

Form fields, also known as AcroForms, are a collection of fields such as text boxes, checkboxes, radio buttons, drop-down lists, push buttons, and more that will gather information interactively from the user.

### Widget Annotation

One of the most important ideas to understand is the appearance (how it is displayed) of a form field is independent of the field itself and exists as a widget annotation. In fact, there can be multiple widget annotations for a single field. This gives the freedom to present a field appearance over multiple pages or even multiple times on the same page of a document.

Annotations and fields should be added to the document only after the document has finished loading. This can be done by listening for the [DocumentViewer.documentLoaded](https://sdk.apryse.com/api/web/Core.DocumentViewer.html#event:documentLoaded__anchor) event:

{% tabs %}
{% tab title="JavaScript (SDK v8.0+)" %}
{% code lineNumbers="true" %}

```js
WebViewer(...)
  .then(instance => {
    const { documentViewer } = instance.Core;
    documentViewer.addEventListener('documentLoaded', () => {
      // create field and widget annotations here
    });
  });
```

{% endcode %}

[DocumentViewer#documentLoaded](https://sdk.apryse.com/api/web/Core.DocumentViewer.html#event:documentLoaded__anchor)
{% endtab %}

{% tab title="JavaScript (SDK v6.0+)" %}
{% code lineNumbers="true" %}

```js
WebViewer(...)
  .then(instance => {
    const { docViewer, annotManager, Annotations } = instance;
    docViewer.on('documentLoaded', () => {
      // create field and widget annotations here
    });
  });
```

{% endcode %}

[DocumentViewer#documentLoaded](https://sdk.apryse.com/api/web/Core.DocumentViewer.html#event:documentLoaded__anchor)
{% endtab %}
{% endtabs %}

## Types of Fields to Add

{% tabs %}
{% tab title="Text" %}

### Create Text Fields

Text fields and widget annotations can be added programmatically. There are several properties and widget flags as highlighted below:

### Text widget flags

| Widget Flag           | Description                                                                                                                                                               | Unique to text? |
| --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------- |
| READ\_ONLY            | The field value cannot be changed.                                                                                                                                        | No              |
| REQUIRED              | The field must have a value when exported.                                                                                                                                | No              |
| MULTILINE             | The field may contain multiple lines of text.                                                                                                                             | Yes             |
| COMB                  | The field shall be automatically divided into as many equally spaced positions as the value of the max length.                                                            | Yes             |
| DO\_NOT\_SCROLL       | The field shall not scroll (horizontally for single-line fields, vertically for multiple-line fields) to accommodate more text than fits within its annotation rectangle. | Yes             |
| DO\_NOT\_SPELL\_CHECK | The field text shall not be spell-checked.                                                                                                                                | Yes             |

### Text widget sample code

{% tabs %}
{% tab title="JavaScript (SDK v8.0+)" %}
{% code lineNumbers="true" %}

```js
WebViewer(...)
.then(instance => {
  const { annotationManager, Annotations, documentViewer } = instance.Core;
  const { WidgetFlags } = Annotations;

  documentViewer.addEventListener('documentLoaded', () => {
    // Sets flags for the text widget.
    const flags = new WidgetFlags();
    flags.set(WidgetFlags.REQUIRED, true);
    flags.set(WidgetFlags.MULTILINE, true);

    // Creates a text form field.
    const field = new Annotations.Forms.Field('TextFormField 1', {
      type: 'Tx',
      defaultValue: 'Default Value',
      flags,
    });

    // Creates a text widget annotation.
    const widgetAnnot = new Annotations.TextWidgetAnnotation(field);
    widgetAnnot.PageNumber = 1;
    widgetAnnot.X = 100;
    widgetAnnot.Y = 100;
    widgetAnnot.Width = 200;
    widgetAnnot.Height = 50;

    // Add form field to field manager and widget annotation to annotation manager.
    annotationManager.getFieldManager().addField(field);
    annotationManager.addAnnotation(widgetAnnot);
    annotationManager.drawAnnotationsFromList([widgetAnnot]);
  });
});
```

{% endcode %}

[Annotations.WidgetFlags](https://sdk.apryse.com/api/web/Core.Annotations.WidgetFlags.html) [Annotations.Forms.Field](https://sdk.apryse.com/api/web/Core.Annotations.Forms.Field.html) [Annotations.TextWidgetAnnotation](https://sdk.apryse.com/api/web/Core.Annotations.TextWidgetAnnotation.html#TextWidgetAnnotation__anchor) [Annotations.WidgetAnnotation](https://sdk.apryse.com/api/web/Core.Annotations.WidgetAnnotation.html) [AnnotationManager.addAnnotation](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#addAnnotation__anchor) [AnnotationManager.drawAnnotationsFromList](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#drawAnnotationsFromList__anchor) [AnnotationManager.getFieldManager](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#getFieldManager__anchor) [FieldManager.addField](https://sdk.apryse.com/api/web/Core.Annotations.Forms.FieldManager.html#addField__anchor)
{% endtab %}

{% tab title="JavaScript (SDK v6.0+)" %}
{% code lineNumbers="true" %}

```js
WebViewer(...)
  .then(instance => {
    const { docViewer, annotManager, Annotations } = instance;

    docViewer.on('documentLoaded', () => {
      // create field and widget annotations here
    });
  });
```

{% endcode %}

[DocumentViewer#documentLoaded](https://sdk.apryse.com/api/web/Core.DocumentViewer.html#event:documentLoaded__anchor)
{% endtab %}
{% endtabs %}
{% endtab %}

{% tab title="Signature" %}

### Create Signature Fields

Signature fields and widget annotations can be added programmatically. There are several properties and widget flags as highlighted below:

### Signature widget flags

| Widget flag | Description                                | Unique to signature? |
| ----------- | ------------------------------------------ | -------------------- |
| READ\_ONLY  | The field value cannot be changed.         | No                   |
| REQUIRED    | The field must have a value when exported. | No                   |

### Signature sample code

{% tabs %}
{% tab title="JavaScript (SDK v8.0+)" %}
{% code lineNumbers="true" %}

```js
WebViewer(...)
.then(instance => {
  const { annotationManager, Annotations, documentViewer } = instance.Core;
  const { WidgetFlags } = Annotations;

  documentViewer.addEventListener('documentLoaded', () => {
    // Sets flags for the signature widget.
    const flags = new WidgetFlags();
    flags.set(WidgetFlags.REQUIRED, true);

    // Creates a signature form field.
    const field = new Annotations.Forms.Field('SignatureFormField 1', { 
      type: 'Sig', 
      flags,
    });

    // Creates a signature widget annotation.
    const widgetAnnot = new Annotations.SignatureWidgetAnnotation(field, {
      appearance: '_DEFAULT',
      appearances: {
        _DEFAULT: {
          Normal: {
            // Optionally can pass image data to appearance.
            // data: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAYdEVYdFNvZnR3YXJlAHBhaW50Lm5ldCA0LjEuMWMqnEsAAAANSURBVBhXY/j//z8DAAj8Av6IXwbgAAAAAElFTkSuQmCC',
            offset: {
              x: 100,
              y: 100,
            },
          },
        },
      },
    });

    widgetAnnot.PageNumber = 1;
    widgetAnnot.X = 100;
    widgetAnnot.Y = 100;
    widgetAnnot.Width = 100;
    widgetAnnot.Height = 50;

    // Add form field to field manager and widget annotation to annotation manager.
    annotationManager.getFieldManager().addField(field);
    annotationManager.addAnnotation(widgetAnnot);
    annotationManager.drawAnnotationsFromList([widgetAnnot]);
  });
});
```

{% endcode %}

[Annotations.WidgetFlags](https://sdk.apryse.com/api/web/Core.Annotations.WidgetFlags.html) [Annotations.Forms.Field](https://sdk.apryse.com/api/web/Core.Annotations.Forms.Field.html) [Annotations.SignatureWidgetAnnotation](https://sdk.apryse.com/api/web/Core.Annotations.SignatureWidgetAnnotation.html#SignatureWidgetAnnotation__anchor) [Annotations.WidgetAnnotation](https://sdk.apryse.com/api/web/Core.Annotations.WidgetAnnotation.html) [AnnotationManager.addAnnotation](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#addAnnotation__anchor) [AnnotationManager.drawAnnotationsFromList](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#drawAnnotationsFromList__anchor) [AnnotationManager.getFieldManager](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#getFieldManager__anchor) [FieldManager.addField](https://sdk.apryse.com/api/web/Core.Annotations.Forms.FieldManager.html#addField__anchor)
{% endtab %}

{% tab title="JavaScript (SDK v6.0+)" %}
{% code lineNumbers="true" %}

```js
WebViewer(...)
  .then(instance => {
    const { docViewer, annotManager, Annotations } = instance;

    docViewer.on('documentLoaded', () => {
      // create field and widget annotations here
    });
  });
```

{% endcode %}

[DocumentViewer#documentLoaded](https://sdk.apryse.com/api/web/Core.DocumentViewer.html#event:documentLoaded__anchor)
{% endtab %}
{% endtabs %}

## Creating a signature widget to accept initials

Starting in WebViewer 8.9, you can create a Signature Widget that accepts initials. If a signature widget is flagged as `requiresInitials`, it will apply the initials created by the user in the [signature modal](/web/digital-signature/interacting-with-signature-field.md#applying-initials-to-a-signature-field). This optional parameter can be passed when instantiating a Signature Widget. Please note that the initials feature must be enabled in order for this to be displayed in the viewer. For a sample on how to do this refer to [this guide](/web/digital-signature/signature-tool.md#initials-as-signature).

{% code lineNumbers="true" %}

```js
WebViewer(...)
.then(instance => {
  const { annotationManager, Annotations } = instance.Core;
  const { WidgetFlags } = Annotations;

  // myBtn is your own custom button
  document.getElementById('myBtn').addEventListener('click', () => {

    // set flags for required
    const flags = new WidgetFlags();
    flags.set('Required', true);

    // create a form field
    const field = new Annotations.Forms.Field("some signature field name", { 
      type: 'Sig', 
      flags,
    });

    // create a widget annotation
    const widgetAnnot = new Annotations.SignatureWidgetAnnotation(field, {
      appearance: '_DEFAULT',
      appearances: {
        _DEFAULT: {
          Normal: {
            offset: {
              x: 100,
              y: 100,
            },
          },
        },
      },
      // If this option is passed, the widget will apply any 
      // initials created by the user in the Signature Modal
      requiresInitials: true,
    });
    
    // to show the 'initials' field indicator on widget import
    widgetAnnot.setCustomData('trn-signature-type', 'initialsSignature')

    // set position and size
    widgetAnnot.PageNumber = 1;
    widgetAnnot.X = 100;
    widgetAnnot.Y = 100;
    widgetAnnot.Width = 50;
    widgetAnnot.Height = 20;

    //add the form field and widget annotation
    annotationManager.getFieldManager().addField(field);
    annotationManager.addAnnotation(widgetAnnot);
    annotationManager.drawAnnotationsFromList([widgetAnnot]);
  });
});
```

{% endcode %}

[Annotations.WidgetFlags](https://sdk.apryse.com/api/web/Core.Annotations.WidgetFlags.html) [Annotations.Forms.Field](https://sdk.apryse.com/api/web/Core.Annotations.Forms.Field.html) [Annotations.SignatureWidgetAnnotation](https://sdk.apryse.com/api/web/Core.Annotations.SignatureWidgetAnnotation.html#SignatureWidgetAnnotation__anchor) [Annotations.WidgetAnnotation](https://sdk.apryse.com/api/web/Core.Annotations.WidgetAnnotation.html) [AnnotationManager.addAnnotation](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#addAnnotation__anchor) [AnnotationManager.drawAnnotationsFromList](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#drawAnnotationsFromList__anchor) [AnnotationManager.getFieldManager](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#getFieldManager__anchor) [FieldManager.addField](https://sdk.apryse.com/api/web/Core.Annotations.Forms.FieldManager.html#addField__anchor)
{% endtab %}

{% tab title="Checkbox" %}

### Create Checkbox Fields

Checkbox fields and widget annotations can be added programmatically. There are several properties and widget flags as highlighted below:

### Checkbox caption options

| Caption | Value | Result                                                                                                                                                                                                                                        |
| ------- | ----- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Check   | `''`  | ![](https://3532544125-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FX9YnTSKIHvV7m0A36LbO%2Fuploads%2Fgit-blob-3e31842408ff7db682512a8ec2543c6820622f4b%2F6e9b4a7c300fd35c960a0f252b62951b7a15e0d3-44x44.png?alt=media) |
| Circle  | `l`   | ![](https://3532544125-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FX9YnTSKIHvV7m0A36LbO%2Fuploads%2Fgit-blob-1e51147631df9f7c4eedf6863400c71d5a3c838a%2Fc02423ddbf558c41ff860be127563251e248260a-42x42.png?alt=media) |
| Cross   | `8`   | ![](https://3532544125-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FX9YnTSKIHvV7m0A36LbO%2Fuploads%2Fgit-blob-2f129107726d54976412ca2b2e80c187d99e63f2%2Ffb4c3334c7a3d41d4089649d3fbb7e090a63a4e2-44x44.png?alt=media) |
| Diamond | `u`   | ![](https://3532544125-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FX9YnTSKIHvV7m0A36LbO%2Fuploads%2Fgit-blob-0b6928c80e550e0d50408e15242aa4a112ea05f8%2F0af881f9681839c0a5e79d2b7aa7ed4f045950a4-44x44.png?alt=media) |
| Square  | `n`   | ![](https://3532544125-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FX9YnTSKIHvV7m0A36LbO%2Fuploads%2Fgit-blob-138fa4c6562b2ab99c00264709d632c5cc6abfa9%2F296b7872446c6248ecfc99c46937c2ba1209dd72-45x45.png?alt=media) |
| Star    | `H`   | ![](https://3532544125-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FX9YnTSKIHvV7m0A36LbO%2Fuploads%2Fgit-blob-b365fec091322c3c3941b913a7650e5f14f2424b%2Feb9329c7d8a6541743453738b2655392abf399cd-44x44.png?alt=media) |

### Checkbox widget flags

| Widget flag | Description                                | Unique to checkbox? |
| ----------- | ------------------------------------------ | ------------------- |
| READ\_ONLY  | The field value cannot be changed.         | No                  |
| REQUIRED    | The field must have a value when exported. | No                  |

### Checkbox sample code

{% tabs %}
{% tab title="JavaScript (SDK v8.0+)" %}
{% code lineNumbers="true" %}

```js
WebViewer(...)
.then(instance => {
  const { annotationManager, Annotations, documentViewer } = instance.Core;
  const { WidgetFlags } = Annotations;

  documentViewer.addEventListener('documentLoaded', () => {
    // Sets flags for the checkbox widget.
    const flags = new WidgetFlags();
    flags.set(WidgetFlags.REQUIRED, true);

    // Creates a checkbox form field.
    const field = new Annotations.Forms.Field('CheckboxField 1', {
      type: 'Btn',
      value: 'Off',
      flags,
    });

    // Creates a checkbox widget annotation.
    const widgetAnnot = new Annotations.CheckButtonWidgetAnnotation(field, {
      appearance: 'Off',
      appearances: {
        Off: {},
        Yes: {},
      },
      captions: {
        Normal: '' // Uses the check symbol for selected caption.
      }
    });

    widgetAnnot.PageNumber = 1;
    widgetAnnot.X = 100;
    widgetAnnot.Y = 100;
    widgetAnnot.Width = 25;
    widgetAnnot.Height = 25;

    // Add form field to field manager and widget annotation to annotation manager.
    annotationManager.getFieldManager().addField(field);
    annotationManager.addAnnotation(widgetAnnot);
    annotationManager.drawAnnotationsFromList([widgetAnnot]);
  });
});
```

{% endcode %}

[Annotations.WidgetFlags](https://sdk.apryse.com/api/web/Core.Annotations.WidgetFlags.html) [Annotations.Forms.Field](https://sdk.apryse.com/api/web/Core.Annotations.Forms.Field.html) [Annotations.CheckButtonWidgetAnnotation](https://sdk.apryse.com/api/web/Core.Annotations.CheckButtonWidgetAnnotation.html#CheckButtonWidgetAnnotation__anchor) [Annotations.WidgetAnnotation](https://sdk.apryse.com/api/web/Core.Annotations.WidgetAnnotation.html) [AnnotationManager.addAnnotation](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#addAnnotation__anchor) [AnnotationManager.drawAnnotationsFromList](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#drawAnnotationsFromList__anchor) [AnnotationManager.getFieldManager](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#getFieldManager__anchor) [FieldManager.addField](https://sdk.apryse.com/api/web/Core.Annotations.Forms.FieldManager.html#addField__anchor)
{% endtab %}

{% tab title="JavaScript (SDK v6.0+)" %}
{% code lineNumbers="true" %}

```js
WebViewer(...)
  .then(instance => {
    const { docViewer, annotManager, Annotations } = instance;

    docViewer.on('documentLoaded', () => {
      // create field and widget annotations here
    });
  });
```

{% endcode %}

[DocumentViewer#documentLoaded](https://sdk.apryse.com/api/web/Core.DocumentViewer.html#event:documentLoaded__anchor)
{% endtab %}
{% endtabs %}
{% endtab %}

{% tab title="Combobox" %}
Create Combobox Fields

Combobox (choice) fields and widget annotations can be added programmatically. There are several properties and widget flags as highlighted below:

### Combobox widget flags

| Widget flag   | Description                                                              | Unique to combobox? |
| ------------- | ------------------------------------------------------------------------ | ------------------- |
| READ\_ONLY    | The field value cannot be changed.                                       | No                  |
| REQUIRED      | The field must have a value when exported.                               | No                  |
| COMBO         | The field is a combobox. Must be **true**.                               | No                  |
| MULTI\_SELECT | The field can have multiple selected values.                             | No                  |
| EDIT          | If true, the combobox will include an editable text box with a dropdown. | Yes                 |

### Combobox sample code

{% tabs %}
{% tab title="JavaScript (SDK v8.0+)" %}
{% code lineNumbers="true" %}

```js
WebViewer(...)
.then(instance => {
  const { annotationManager, Annotations, documentViewer } = instance.Core;
  const { WidgetFlags } = Annotations;

  documentViewer.addEventListener('documentLoaded', () => {
    // Sets flags for the combobox widget.
    const flags = new WidgetFlags();
    flags.set(WidgetFlags.COMBO, true);
    flags.set(WidgetFlags.REQUIRED, true);

    // Define the available options.
    const comboOptions = [
      { value: '1', displayValue: 'one' },
      { value: '2', displayValue: 'two' },
      { value: '3', displayValue: 'three' }
    ];

    // Specify a font-family and font size.
    const font = new Annotations.Font({ name: 'Helvetica', size: 12 });

    // Creates a combobox form field.
    const field = new Annotations.Forms.Field('ComboBoxField 1', {
      flags,
      font,
      type: 'Ch',
      options: comboOptions,
      value: comboOptions[0].value,
    });

    // Creates a combobox widget annotation.
    const widgetAnnot = new Annotations.ChoiceWidgetAnnotation(field);
    widgetAnnot.PageNumber = 1;
    widgetAnnot.X = 100;
    widgetAnnot.Y = 100;
    widgetAnnot.Width = 200;
    widgetAnnot.Height = 25;

    // Add form field to field manager and widget annotation to annotation manager.
    annotationManager.getFieldManager().addField(field);
    annotationManager.addAnnotation(widgetAnnot);
    annotationManager.drawAnnotationsFromList([widgetAnnot]);
  });
});
```

{% endcode %}

[Annotations.WidgetFlags](https://sdk.apryse.com/api/web/Core.Annotations.WidgetFlags.html) [Annotations.Forms.Field](https://sdk.apryse.com/api/web/Core.Annotations.Forms.Field.html) [Annotations.ChoiceWidgetAnnotation](https://sdk.apryse.com/api/web/Core.Annotations.ChoiceWidgetAnnotation.html#ChoiceWidgetAnnotation__anchor) [Annotations.WidgetAnnotation](https://sdk.apryse.com/api/web/Core.Annotations.WidgetAnnotation.html) [AnnotationManager.addAnnotation](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#addAnnotation__anchor) [AnnotationManager.drawAnnotationsFromList](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#drawAnnotationsFromList__anchor) [AnnotationManager.getFieldManager](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#getFieldManager__anchor) [FieldManager.addField](https://sdk.apryse.com/api/web/Core.Annotations.Forms.FieldManager.html#addField__anchor)
{% endtab %}

{% tab title="JavaScript (SDK v6.0+)" %}
{% code lineNumbers="true" %}

```js
WebViewer(...)
  .then(instance => {
    const { docViewer, annotManager, Annotations } = instance;

    docViewer.on('documentLoaded', () => {
      // create field and widget annotations here
    });
  });
```

{% endcode %}

[DocumentViewer#documentLoaded](https://sdk.apryse.com/api/web/Core.DocumentViewer.html#event:documentLoaded__anchor)
{% endtab %}
{% endtabs %}
{% endtab %}

{% tab title="Listbox" %}
Create Listbox Fields

Listbox fields and widget annotations can be added programmatically. There are several properties and widget flags as highlighted below:

### Listbox widget flags

| Widget flag   | Description                                  | Unique to listbox? |
| ------------- | -------------------------------------------- | ------------------ |
| READ\_ONLY    | The field value cannot be changed.           | No                 |
| REQUIRED      | The field must have a value when exported.   | No                 |
| COMBO         | The field is a listbox. Must be **false**.   | No                 |
| MULTI\_SELECT | The field can have multiple selected values. | No                 |

### Listbox sample code

{% tabs %}
{% tab title="JavaScript (SDK v8.0+)" %}
{% code lineNumbers="true" %}

```js
WebViewer(...)
.then(instance => {
  const { annotationManager, Annotations, documentViewer } = instance.Core;
  const { WidgetFlags } = Annotations;

  documentViewer.addEventListener('documentLoaded', () => {
    // Sets flags for the listbox widget.
    const flags = new WidgetFlags();
    flags.set(WidgetFlags.COMBO, false);
    flags.set(WidgetFlags.MULTI_SELECT, true);
    flags.set(WidgetFlags.REQUIRED, true);

    // Define the available options.
    const listOptions = [
      { value: '1', displayValue: 'one' },
      { value: '2', displayValue: 'two' },
      { value: '3', displayValue: 'three' }
    ];

    // Specify a font-family and font size.
    const font = new Annotations.Font({ name: 'Helvetica', size: 12 });

    // Creates a listbox form field.
    const field = new Annotations.Forms.Field('ListBoxField 1', {
      flags,
      font,
      type: 'Ch',
      options: listOptions,
      value: listOptions[0].value,
    });

    // Creates a listbox widget annotation.
    const widgetAnnot = new Annotations.ListWidgetAnnotation(field);
    widgetAnnot.PageNumber = 1;
    widgetAnnot.X = 100;
    widgetAnnot.Y = 100;
    widgetAnnot.Width = 200;
    widgetAnnot.Height = 50;

    // Add form field to field manager and widget annotation to annotation manager.
    annotationManager.getFieldManager().addField(field);
    annotationManager.addAnnotation(widgetAnnot);
    annotationManager.drawAnnotationsFromList([widgetAnnot]);
  });
});
```

{% endcode %}

[Annotations.WidgetFlags](https://sdk.apryse.com/api/web/Core.Annotations.WidgetFlags.html) [Annotations.Forms.Field](https://sdk.apryse.com/api/web/Core.Annotations.Forms.Field.html) [Annotations.ListWidgetAnnotation](https://sdk.apryse.com/api/web/Core.Annotations.ListWidgetAnnotation.html#ListWidgetAnnotation__anchor) [Annotations.WidgetAnnotation](https://sdk.apryse.com/api/web/Core.Annotations.WidgetAnnotation.html) [AnnotationManager.addAnnotation](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#addAnnotation__anchor) [AnnotationManager.drawAnnotationsFromList](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#drawAnnotationsFromList__anchor) [AnnotationManager.getFieldManager](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#getFieldManager__anchor) [FieldManager.addField](https://sdk.apryse.com/api/web/Core.Annotations.Forms.FieldManager.html#addField__anchor)
{% endtab %}

{% tab title="JavaScript (SDK v6.0+)" %}
{% code lineNumbers="true" %}

```js
WebViewer(...)
  .then(instance => {
    const { docViewer, annotManager, Annotations } = instance;

    docViewer.on('documentLoaded', () => {
      // create field and widget annotations here
    });
  });
```

{% endcode %}

[DocumentViewer#documentLoaded](https://sdk.apryse.com/api/web/Core.DocumentViewer.html#event:documentLoaded__anchor)
{% endtab %}
{% endtabs %}
{% endtab %}

{% tab title="Radio Button" %}

### Create Radio Buttons

Radio button fields and widget annotations can be added programmatically. There are several properties and widget flags as highlighted below:

### Radio button widget flags

| Widget flag         | Description                                       | Unique to radio? |
| ------------------- | ------------------------------------------------- | ---------------- |
| READ\_ONLY          | The field value cannot be changed.                | No               |
| REQUIRED            | The field must have a value when exported.        | No               |
| RADIO               | This must be **true** otherwise it is a checkbox. | No               |
| NO\_TOGGLE\_TO\_OFF | If true only one radio button can be selected.    | Yes              |

### Radio button sample code

{% tabs %}
{% tab title="JavaScript (SDK v8.0+)" %}
{% code lineNumbers="true" %}

```js
WebViewer(...)
.then(instance => {
  const { annotationManager, Annotations, documentViewer } = instance.Core;
  const { WidgetFlags } = Annotations;

  documentViewer.addEventListener('documentLoaded', () => {
    // Sets flags for the combobox widget.
    const flags = new WidgetFlags();
    flags.set(WidgetFlags.RADIO, true);
    flags.set(WidgetFlags.NO_TOGGLE_TO_OFF, true);
    flags.set(WidgetFlags.REQUIRED, true);

    // Creates a radio button group form field.
    const field = new Annotations.Forms.Field('RadioButtonGroupName 1', {
      type: 'Btn',
      value: 'Off',
      flags
    });

    // Create a radio widget button.
    const radioButton1 = new Annotations.RadioButtonWidgetAnnotation(field, {
      appearance: 'Off',
      appearances: {
        Off: {},
        First: {},
      },
    });

    // Create another radio button widget.
    const radioButton2 = new Annotations.RadioButtonWidgetAnnotation(field, {
      appearance: 'Off',
      appearances: {
        Off: {},
        Second: {},
      },
    });

    radioButton1.PageNumber = 1;
    radioButton1.X = 100;
    radioButton1.Y = 100;
    radioButton1.Width = 25;
    radioButton1.Height = 25;

    radioButton2.PageNumber = 1;
    radioButton2.X = 150;
    radioButton2.Y = 150;
    radioButton2.Width = 25;
    radioButton2.Height = 25;

    // Add form field to field manager and widget annotation to annotation manager.
    annotationManager.getFieldManager().addField(field);
    annotationManager.addAnnotation(radioButton1);
    annotationManager.addAnnotation(radioButton2);
    annotationManager.drawAnnotationsFromList([radioButton1, radioButton2]);
  });
});
```

{% endcode %}

[Annotations.WidgetFlags](https://sdk.apryse.com/api/web/Core.Annotations.WidgetFlags.html) [Annotations.Forms.Field](https://sdk.apryse.com/api/web/Core.Annotations.Forms.Field.html) [Annotations.RadioButtonWidgetAnnotation](https://sdk.apryse.com/api/web/Core.Annotations.RadioButtonWidgetAnnotation.html#RadioButtonWidgetAnnotation__anchor) [Annotations.WidgetAnnotation](https://sdk.apryse.com/api/web/Core.Annotations.WidgetAnnotation.html) [AnnotationManager.addAnnotation](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#addAnnotation__anchor) [AnnotationManager.drawAnnotationsFromList](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#drawAnnotationsFromList__anchor) [AnnotationManager.getFieldManager](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#getFieldManager__anchor) [FieldManager.addField](https://sdk.apryse.com/api/web/Core.Annotations.Forms.FieldManager.html#addField__anchor)
{% endtab %}

{% tab title="JavaScript (SDK v6.0+)" %}
{% code lineNumbers="true" %}

```js
WebViewer(...)
  .then(instance => {
    const { docViewer, annotManager, Annotations } = instance;

    docViewer.on('documentLoaded', () => {
      // create field and widget annotations here
    });
  });
```

{% endcode %}

[DocumentViewer#documentLoaded](https://sdk.apryse.com/api/web/Core.DocumentViewer.html#event:documentLoaded__anchor)
{% endtab %}
{% endtabs %}
{% endtab %}

{% tab title="Date Picker" %}

### Create Date Picker Fields

For form fields that expect a date to be input, WebViewer provides an interactive date picker widget to select a date from a calendar. Users can still type the date, but the date field can also be populated by using the calendar.

The calendar will automatically set the correct date format for the field so the user doesn't need to worry about entering the date in a specific format.

![](https://3532544125-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FX9YnTSKIHvV7m0A36LbO%2Fuploads%2Fgit-blob-07ff27f095f646d11cf3b16fb70df123bde03b40%2F5225f1341cd9a1b63d72469b70147feccff84dfd-650x514.gif?alt=media)

Date picker fields and widget annotations can be added programmatically. There are several properties and widget flags as highlighted below:

### Date picker widget flags

| Widget flag | Description                                | Unique to date picker? |
| ----------- | ------------------------------------------ | ---------------------- |
| READ\_ONLY  | The field value cannot be changed.         | No                     |
| REQUIRED    | The field must have a value when exported. | No                     |

### Date picker sample code

{% tabs %}
{% tab title="JavaScript (SDK v8.0+)" %}
{% code lineNumbers="true" %}

```js
WebViewer(...)
.then(instance => {
  const { annotationManager, Annotations, documentViewer } = instance.Core;
  const { WidgetFlags } = Annotations;

  documentViewer.addEventListener('documentLoaded', () => {
    // Sets flags for the date picker widget.
    const flags = new WidgetFlags();
    flags.set(WidgetFlags.REQUIRED, true);

    // Specify a font-family and font size.
    const font = new Annotations.Font({ name: 'Helvetica', size: 12 });

    // Creates a date picker form field.
    const field = new Annotations.Forms.Field('DatePickerField 1', {
      flags,
      font,
      type: 'Tx', // Date pickers are considered 'text' fields.
    });

    // Creates a date picker widget annotation.
    const widgetAnnot = new Annotations.DatePickerWidgetAnnotation(field);
    widgetAnnot.PageNumber = 1;
    widgetAnnot.X = 25;
    widgetAnnot.Y = 25;
    widgetAnnot.Width = 100;
    widgetAnnot.Height = 25;

    // Add form field to field manager and widget annotation to annotation manager.
    annotationManager.getFieldManager().addField(field);
    annotationManager.addAnnotation(widgetAnnot);
    annotationManager.drawAnnotationsFromList([widgetAnnot]);
  });
});
```

{% endcode %}

[Annotations.WidgetFlags](https://sdk.apryse.com/api/web/Core.Annotations.WidgetFlags.html) [Annotations.Forms.Field](https://sdk.apryse.com/api/web/Core.Annotations.Forms.Field.html) [Annotations.DatePickerWidgetAnnotation](https://sdk.apryse.com/api/web/Core.Annotations.DatePickerWidgetAnnotation.html#DatePickerWidgetAnnotation__anchor) [Annotations.WidgetAnnotation](https://sdk.apryse.com/api/web/Core.Annotations.WidgetAnnotation.html) [AnnotationManager.addAnnotation](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#addAnnotation__anchor) [AnnotationManager.drawAnnotationsFromList](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#drawAnnotationsFromList__anchor) [AnnotationManager.getFieldManager](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#getFieldManager__anchor) [FieldManager.addField](https://sdk.apryse.com/api/web/Core.Annotations.Forms.FieldManager.html#addField__anchor)
{% endtab %}

{% tab title="JavaScript (SDK v6.0+)" %}
{% code lineNumbers="true" %}

```js
WebViewer(...)
  .then(instance => {
    const { docViewer, annotManager, Annotations } = instance;

    docViewer.on('documentLoaded', () => {
      // create field and widget annotations here
    });
  });
```

{% endcode %}

[DocumentViewer#documentLoaded](https://sdk.apryse.com/api/web/Core.DocumentViewer.html#event:documentLoaded__anchor)
{% endtab %}
{% endtabs %}

### Filling date field programmatically

Just like other PDF form fields, the date field can also be filled programmatically using the [fieldManager](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#getFieldManager__anchor) or using the [Annotations.DatePickerWidgetAnnotation](https://sdk.apryse.com/api/web/Core.Annotations.DatePickerWidgetAnnotation.html) instance.

Here is an example of filling date field programmatically:

{% code lineNumbers="true" %}

```js
WebViewer(...)
  .then(instance => {
    const { annotationManager, documentViewer } = instance.Core;
    documentViewer.addEventListener('annotationsLoaded', () => {
      // replace with id of date field in your document
      const dateFieldId = 'DatePicker_1';
      const field = annotationManager.getFieldManager().getField(dateFieldId);
      field.setValue('6/15/20');
      const widget = field.widgets[0];
      widget.getDatePicker().show(); // open date picker widget
      widget.getDatePicker().setDate('6/17/20');
      field.setValue('6/7/20');
      widget.refreshDatePicker(); // refresh widget
    });
    // ...
});
```

{% endcode %}

[AnnotationManager.getFieldManager](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#getFieldManager__anchor) [FieldManager.getField](https://sdk.apryse.com/api/web/Core.Annotations.Forms.FieldManager.html#getField__anchor) [Annotations.WidgetFlags](https://sdk.apryse.com/api/web/Core.Annotations.WidgetFlags.html) [Annotations.DatePickerWidgetAnnotation.getDatePicker](https://sdk.apryse.com/api/web/Core.Annotations.DatePickerWidgetAnnotation.html#getDatePicker__anchor)

### Date picker internationalization

The default i18n configuration format looks like this:

{% code lineNumbers="true" %}

```js
WebViewer(...)
  .then(instance => {
    const { Annotations } = instance.Core;
    const { DatePickerWidgetAnnotation } = Annotations;
    DatePickerWidgetAnnotation.datePickerOptions.i18n = {
      previousMonth : 'Previous Month',
      nextMonth     : 'Next Month',
      months        : ['January','February','March','April','May','June','July',
        'August','September','October','November','December'],
      weekdays      : ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday',
        'Saturday'],
      weekdaysShort : ['Sun','Mon','Tue','Wed','Thu','Fri','Sat']
    }
    DatePickerWidgetAnnotation.datePickerOptions.firstDay = 0;
    DatePickerWidgetAnnotation.datePickerOptions.isRTL = false;
   // ...
});
```

{% endcode %}

You must provide 12 months and 7 weekdays (with abbreviations). Always specify weekdays in this order with Sunday first. You can change the `firstDay` option to reorder if necessary (0: Sunday, 1: Monday, etc). You can also set `isRTL` to true for languages that are read from right-to-left.
{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.apryse.com/web/forms/create-fields.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
