> 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/salesforce/forms/forms/create-checkbox-field.md).

# Create checkbox field and checkbox widget annotation using JavaScript

Learn how to create a new checkbox field with required edit flags and a checkbox widget annotation in PDF forms. Explore full sample code for adding form fields, signatures, text fields, and checkboxe

To create a new checkbox field with required edit flags and a checkbox widget annotation.

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

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

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

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

    // set font type
    const font = new Annotations.Font({ name: 'Helvetica' });

    // create a form field
    const field = new Annotations.Forms.Field("some checkbox field name", {
      type: 'Btn',
      value: 'Off',
      flags,
      font: font,
    });

    // create a widget annotation
    // caption options are:
    // "4" = Tick
    // "l" = Circle
    // "8" = Cross
    // "u" = Diamond
    // "n" = Square
    // "H" = Star
    // ""  = Check
    const widgetAnnot = new Annotations.CheckButtonWidgetAnnotation(field, {
      appearance: 'Off',
      appearances: {
        Off: {},
        Yes: {},
      },
      captions: {
        Normal: "" // Check
      }
    });

    // 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.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 { annotManager, Annotations } = instance;

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

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

    // set font type
    const font = new Annotations.Font({ name: 'Helvetica' });

    // create a form field
    const field = new Annotations.Forms.Field("some checkbox field name", {
      type: 'Btn',
      value: 'Off',
      flags,
      font: font,
    });

    // create a widget annotation
    const widgetAnnot = new Annotations.CheckButtonWidgetAnnotation(field, {
      appearance: 'Off',
      appearances: {
        Off: {},
        Yes: {},
      },
    });

    // 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
    annotManager.getFieldManager().addField(field);
    annotManager.addAnnotation(widgetAnnot);
    annotManager.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 %}
{% endtabs %}

[Create fillable PDF forms](/web/get-started/guides/samples/forms.md#form-builder-demo) Full sample code demonstrating how to add form fields to a PDF. Fields are first added as annotations and then converted to interactive form fields. Add signatures, text fields, checkboxes.

Available [widget flags](https://sdk.apryse.com/api/web/Core.Annotations.WidgetFlags.html) are:

* ReadOnly
* Required
* NoExport
* Multiline
* Password
* NoToggleToOff
* Radio
* PushButton
* Combo
* Edit
* DoNotScroll
* RadiosInUnison


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.apryse.com/salesforce/forms/forms/create-checkbox-field.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
