Section:

Styling PDF form fields

Implementing the WidgetAnnotation's getCustomStyles function allows you to add styling changes to particular types of widget annotations.

1// config.js
2const { Annotations } = instance.Core;
3
4Annotations.WidgetAnnotation.getCustomStyles = widget => {
5 if (widget instanceof Annotations.TextWidgetAnnotation) {
6 // can check widget properties
7 if (widget.fieldName === 'f1-1') {
8 return {
9 'background-color': 'lightgreen'
10 };
11 }
12 return {
13 'background-color': 'lightblue',
14 color: 'brown'
15 };
16 } else if (widget instanceof Annotations.PushButtonWidgetAnnotation) {
17 return {
18 'background-color': 'black',
19 color: 'white'
20 };
21 } else if (widget instanceof Annotations.CheckButtonWidgetAnnotation) {
22 return {
23 'background-color': 'lightgray',
24 opacity: 0.8
25 };
26 }
27};

Implementing the WidgetAnnotation's getContainerCustomStyles function allows you to add styling changes to the container element of the widget annotation.

1// config.js
2const { Annotations } = instance.Core;
3
4Annotations.WidgetAnnotation.getContainerCustomStyles = widget => {
5 if (widget instanceof Annotations.TextWidgetAnnotation) {
6 // can check widget properties
7 if (widget.fieldName === 'f1-1') {
8 return {
9 'background-color': 'lightgreen'
10 };
11 }
12 return {
13 'background-color': 'lightblue',
14 color: 'brown'
15 };
16 } else if (widget instanceof Annotations.PushButtonWidgetAnnotation) {
17 return {
18 'background-color': 'black',
19 color: 'white'
20 };
21 } else if (widget instanceof Annotations.CheckButtonWidgetAnnotation) {
22 return {
23 'background-color': 'lightgray',
24 opacity: 0.8
25 };
26 }
27};

You can also extend the createInnerElement function on widget annotations. This allows you to use your own DOM elements for the display or just to add your own event handlers.

1// config.js
2const { Annotations } = instance.Core;
3
4const createInnerElement = Annotations.CheckButtonWidgetAnnotation.prototype.createInnerElement;
5Annotations.CheckButtonWidgetAnnotation.prototype.createInnerElement = function() {
6 const button = this;
7
8 const el = createInnerElement.apply(this, arguments);
9 el.addEventListener('click', () => {
10 console.log('check button clicked', button.fieldName);
11 });
12
13 return el;
14};

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales