Search results

Focus on a form field of the form after loading in JavaScript (ES5) PDF Viewer control

02 Feb 2023 / 1 minute to read

The PDF Viewer library allows you to focus to the respective form field using the focusFormField() API.

The following steps are used to focus to the respective form field.

Step 1: Follow the steps provided in the link to create a simple PDF Viewer sample.

Step 2: Use the following code sample to focus to the respective form field while loading as well as in a button click.

Copied to clipboard
  <button id="focusFormField">FocusFormField</button>
Copied to clipboard
//Event triggers while clicking the FocusFormField button.
document.getElementById('click').addEventListener('click', function () {
    var formField = viewer.retrieveFormFields();
    //API to bring the form fields in focus.
    viewer.focusFormField(formField[1]);
});
//Event triggers while loading the document.
viewer.documentLoad = (args) => {
    var formField = viewer.retrieveFormFields();
    //API to bring the form fields in focus.
    viewer.focusFormField(formField[1]);
};

View sample in GitHub.