> 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/reusable-content/web/web-form-createlistbox.md).

# web/form/createListbox

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+)" %}

```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]);
  });
});
```

[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+)" %}

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

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

[DocumentViewer#documentLoaded](https://sdk.apryse.com/api/web/Core.DocumentViewer.html#event:documentLoaded__anchor)
{% 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/reusable-content/web/web-form-createlistbox.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.
