> 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/salesforce/forms/form-field-styling.md).

# Styling PDF form fields

Learn how to customize widget annotations with the getCustomStyles and getContainerCustomStyles functions. Extend createInnerElement for unique styling and event handling. Optimize your PDF viewer now

Implementing the [WidgetAnnotation's getCustomStyles function](https://sdk.apryse.com/api/web/Core.Annotations.WidgetAnnotation.html#WidgetAnnotation__anchor) allows you to add styling changes to particular types of widget annotations.

{% tabs %}
{% tab title="JavaScript (SDK v8.0+)" %}
{% code lineNumbers="true" %}

```js
// config.js
const { Annotations } = instance.Core;

Annotations.WidgetAnnotation.getCustomStyles = widget => {
  if (widget instanceof Annotations.TextWidgetAnnotation) {
    // can check widget properties
    if (widget.fieldName === 'f1-1') {
      return {
        'background-color': 'lightgreen'
      };
    }
    return {
      'background-color': 'lightblue',
      color: 'brown'
    };
  } else if (widget instanceof Annotations.PushButtonWidgetAnnotation) {
    return {
      'background-color': 'black',
      color: 'white'
    };
  } else if (widget instanceof Annotations.CheckButtonWidgetAnnotation) {
    return {
      'background-color': 'lightgray',
      opacity: 0.8
    };
  }
};
```

{% endcode %}

[Annotations.WidgetAnnotation](https://sdk.apryse.com/api/web/Core.Annotations.WidgetAnnotation.html)
{% endtab %}

{% tab title="JavaScript (SDK v6.0+)" %}
{% code lineNumbers="true" %}

```js
// config.js
const { docViewer, annotManager, Annotations } = instance;

Annotations.WidgetAnnotation.getCustomStyles = widget => {
  if (widget instanceof Annotations.TextWidgetAnnotation) {
    // can check widget properties
    if (widget.fieldName === 'f1-1') {
      return {
        'background-color': 'lightgreen'
      };
    }
    return {
      'background-color': 'lightblue',
      color: 'brown'
    };
  } else if (widget instanceof Annotations.PushButtonWidgetAnnotation) {
    return {
      'background-color': 'black',
      color: 'white'
    };
  } else if (widget instanceof Annotations.CheckButtonWidgetAnnotation) {
    return {
      'background-color': 'lightgray',
      opacity: 0.8
    };
  }
};
```

{% endcode %}

[Annotations.WidgetAnnotation](https://sdk.apryse.com/api/web/Core.Annotations.WidgetAnnotation.html)
{% endtab %}
{% endtabs %}

Implementing the [WidgetAnnotation's getContainerCustomStyles function](https://sdk.apryse.com/api/web/Core.Annotations.WidgetAnnotation.html#WidgetAnnotation__anchor) allows you to add styling changes to the ***container element*** of the widget annotation.

{% tabs %}
{% tab title="JavaScript (SDK v8.0+)" %}
{% code lineNumbers="true" %}

```js
// config.js
const { Annotations } = instance.Core;

Annotations.WidgetAnnotation.getContainerCustomStyles = widget => {
  if (widget instanceof Annotations.TextWidgetAnnotation) {
    // can check widget properties
    if (widget.fieldName === 'f1-1') {
      return {
        'background-color': 'lightgreen'
      };
    }
    return {
      'background-color': 'lightblue',
      color: 'brown'
    };
  } else if (widget instanceof Annotations.PushButtonWidgetAnnotation) {
    return {
      'background-color': 'black',
      color: 'white'
    };
  } else if (widget instanceof Annotations.CheckButtonWidgetAnnotation) {
    return {
      'background-color': 'lightgray',
      opacity: 0.8
    };
  }
};
```

{% endcode %}

[Annotations.WidgetAnnotation](https://sdk.apryse.com/api/web/Core.Annotations.WidgetAnnotation.html)
{% endtab %}

{% tab title="JavaScript (SDK v6.0+)" %}
{% code lineNumbers="true" %}

```js
// config.js
const { docViewer, annotManager, Annotations } = instance;

Annotations.WidgetAnnotation.getContainerCustomStyles = widget => {
  if (widget instanceof Annotations.TextWidgetAnnotation) {
    // can check widget properties
    if (widget.fieldName === 'f1-1') {
      return {
        'background-color': 'lightgreen'
      };
    }
    return {
      'background-color': 'lightblue',
      color: 'brown'
    };
  } else if (widget instanceof Annotations.PushButtonWidgetAnnotation) {
    return {
      'background-color': 'black',
      color: 'white'
    };
  } else if (widget instanceof Annotations.CheckButtonWidgetAnnotation) {
    return {
      'background-color': 'lightgray',
      opacity: 0.8
    };
  }
};
```

{% endcode %}

[Annotations.WidgetAnnotation](https://sdk.apryse.com/api/web/Core.Annotations.WidgetAnnotation.html)
{% endtab %}
{% endtabs %}

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.

{% tabs %}
{% tab title="JavaScript (SDK v8.0+)" %}
{% code lineNumbers="true" %}

```js
// config.js
const { Annotations } = instance.Core;

const createInnerElement = Annotations.CheckButtonWidgetAnnotation.prototype.createInnerElement;
Annotations.CheckButtonWidgetAnnotation.prototype.createInnerElement = function() {
  const button = this;

  const el = createInnerElement.apply(this, arguments);
  el.addEventListener('click', () => {
    console.log('check button clicked', button.fieldName);
  });

  return el;
};
```

{% endcode %}

[Annotations.CheckButtonWidgetAnnotation](https://sdk.apryse.com/api/web/Core.Annotations.CheckButtonWidgetAnnotation.html)
{% endtab %}

{% tab title="JavaScript (SDK v6.0+)" %}
{% code lineNumbers="true" %}

```js
// config.js
const { Annotations } = instance;

const createInnerElement = Annotations.CheckButtonWidgetAnnotation.prototype.createInnerElement;
Annotations.CheckButtonWidgetAnnotation.prototype.createInnerElement = function() {
  const button = this;

  const el = createInnerElement.apply(this, arguments);
  el.addEventListener('click', () => {
    console.log('check button clicked', button.fieldName);
  });

  return el;
};
```

{% endcode %}

[Annotations.CheckButtonWidgetAnnotation](https://sdk.apryse.com/api/web/Core.Annotations.CheckButtonWidgetAnnotation.html)
{% endtab %}
{% endtabs %}


---

# 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/salesforce/forms/form-field-styling.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.
