> 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-datepicker.md).

# web/form/datepicker

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://2401778818-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvUuF7dc8Zt8paqr2K3iP%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+)" %}

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

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

```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 %}

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

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

[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:

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

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.


---

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