Edit PDF Form Fields Using JavaScript

To update a form field or a widget annotation, you can use the instance.update() method. You can also use it to change the widget annotations associated with the form field.

The following example retrieves and updates a form field and its associated widget annotation:

const formFields = await instance.getFormFields();
const formField = formFields.find(
	(formField) => formField.name === 'my form field',
);
const annotations = await instance.getAnnotations(0);
const widget = annotations.find(
	(annotation) => annotation.formFieldName === 'my form field',
);
await instance.update([
	formField.set('required', true),
	widget.set('opacity', 0.5),
]);

Please see the Updating and Removing Annotations section of the Introduction to Annotations guide to learn more about updating annotations.