Section:

Date picker

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 like before, but the date field can now 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.

Apryse Docs Image

Filling date field programmatically

Just like other PDF form fields, the date field can also be filled programmatically using the fieldManager or using the Annotations.DatePickerWidgetAnnotation instance

Here is an example of filling date field programmatically:

1// config.js
2const { annotationManager, documentViewer } = instance.Core;
3documentViewer.addEventListener('annotationsLoaded', () => {
4 // replace with id of date field in your document
5 const dateFieldId = 'DatePicker_1';
6 const field = annotationManager.getFieldManager().getField(dateFieldId);
7 field.setValue('6/15/20');
8
9 const widget = field.widgets[0];
10 widget.getDatePicker().show(); // open date picker widget
11 widget.getDatePicker().setDate('6/17/20');
12
13
14 field.setValue('6/7/20');
15 widget.refreshDatePicker(); // refresh widget
16});

Datepicker Internationalization

The default i18n configuration format looks like this:

1// config.js
2const { Annotations } = instance.Core;
3const { DatePickerWidgetAnnotation } = Annotations;
4
5DatePickerWidgetAnnotation.datePickerOptions.i18n = {
6 previousMonth : 'Previous Month',
7 nextMonth : 'Next Month',
8 months : ['January','February','March','April','May','June','July',
9 'August','September','October','November','December'],
10 weekdays : ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday',
11 'Saturday'],
12 weekdaysShort : ['Sun','Mon','Tue','Wed','Thu','Fri','Sat']
13}
14
15DatePickerWidgetAnnotation.datePickerOptions.firstDay = 0;
16DatePickerWidgetAnnotation.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 right-to-left.

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales