Skip to content

Commit 88f562b

Browse files
1004880: Updated Forms Pending Sections
1 parent e85186f commit 88f562b

9 files changed

Lines changed: 414 additions & 419 deletions

File tree

Document-Processing-toc.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1596,7 +1596,7 @@
15961596
</li>
15971597
<li><a href="/document-processing/pdf/pdf-viewer/javascript-es6/form-designer/custom-data">Add custom data in form fields</a></li>
15981598
<li><a href="/document-processing/pdf/pdf-viewer/javascript-es6/form-designer/group-formfields">Grouping form fields</a></li>
1599-
<li><a href="/document-processing/pdf/pdf-viewer/javascript-es6/form-designer/form-constrain">Form constrains</a></li>
1599+
<li><a href="/document-processing/pdf/pdf-viewer/javascript-es6/form-designer/form-constrain">Form Field Flags</a></li>
16001600
<li><a href="/document-processing/pdf/pdf-viewer/javascript-es6/form-designer/form-validation">Form Validation</a></li>
16011601
<li><a href="/document-processing/pdf/pdf-viewer/javascript-es6/how-to/custom-fonts-ts">Custom fonts</a></li>
16021602
<li><a href="/document-processing/pdf/pdf-viewer/javascript-es6/form-designer/form-field-events">Form Field events</a></li>

Document-Processing/PDF/PDF-Viewer/javascript-es6/form-designer/custom-data.md

Lines changed: 71 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,100 +7,131 @@ control: PDF Viewer
77
documentation: ug
88
---
99

10-
# Add custom data to form fields
10+
# Add Custom Data to PDF Form Fields in TypeScript PDF Viewer
1111

12-
You can associate arbitrary metadata with any form field using the customData property. This is useful for storing business IDs, validation hints, tags, or any app-specific information alongside the field. The data stays with the field object during the viewer session and can be accessed whenever you query or update fields.
12+
The Syncfusion **TypeScript PDF Viewer** allows you to attach **custom application-specific data** to form fields by using the customData property. This enables you to associate business identifiers, tags, validation hints, or workflow metadata with form fields.
1313

14-
N> customData is a free-form object. You control both its shape and how it is used in your application.
14+
The custom data remains linked to the form field throughout the viewer session and can be accessed or updated whenever the field is queried or modified.
1515

16-
## Add custom data when creating fields (programmatically)
16+
This page explains how to:
17+
- [Add custom data when creating form fields](#add-custom-data-while-creating-pdf-form-fields)
18+
- [Define default custom data for fields created using the UI](#set-default-custom-data-for-pdf-form-fields-added-using-ui)
19+
- [Update or replace custom data for existing fields](#update-or-replace-pdf-form-field-custom-data)
20+
- [Read custom data from form fields](#read-custom-data-from-pdf-form-fields)
21+
- [Apply best practices when using custom data](#best-practices)
1722

18-
Pass a customData object in the second parameter of addFormField. You can include any serializable values.
23+
**Key Points**
24+
- customData is a **free form object**; you control its structure.
25+
- Use only **serializable values** such as objects, arrays, strings, numbers, and booleans.
26+
- Custom data does not affect the field appearance or behavior unless consumed by your application logic.
27+
28+
## Add Custom Data While Creating PDF Form Fields
29+
30+
You can attach custom data at the time of field creation by passing a **customData** object in the settings parameter of **addFormField()**.
1931

2032
```ts
21-
import { PdfViewer, Toolbar, Magnification, Navigation, LinkAnnotation, ThumbnailView, BookmarkView,
22-
TextSelection, Annotation, FormDesigner, FormFields, TextFieldSettings } from '@syncfusion/ej2-pdfviewer';
33+
import { PdfViewer, FormDesigner, FormFields, Toolbar, Navigation, Magnification, TextSelection } from '@syncfusion/ej2-pdfviewer';
2334

24-
PdfViewer.Inject(Toolbar, Magnification, Navigation, LinkAnnotation, ThumbnailView, BookmarkView, TextSelection, Annotation, FormDesigner, FormFields);
35+
PdfViewer.Inject(Toolbar, Navigation, Magnification, TextSelection, FormFields, FormDesigner);
2536

26-
const viewer: PdfViewer = new PdfViewer({
37+
const viewer = new PdfViewer({
2738
documentPath: 'https://cdn.syncfusion.com/content/pdf/form-designer.pdf',
2839
resourceUrl: 'https://cdn.syncfusion.com/ej2/31.1.23/dist/ej2-pdfviewer-lib'
2940
});
3041
viewer.appendTo('#pdfViewer');
3142

3243
viewer.documentLoad = () => {
33-
const meta = { businessId: 'C-1024', tags: ['profile', 'kiosk'], requiredRole: 'admin' };
44+
const meta = { businessId: 'C-1024', tags: ['profile','kiosk'], requiredRole: 'admin' };
3445
viewer.formDesignerModule.addFormField('Textbox', {
3546
name: 'Email',
36-
bounds: { X: 146, Y: 229, Width: 200, Height: 24 } as TextFieldSettings,
37-
// Attach any custom metadata your app needs
47+
bounds: { X: 146, Y: 229, Width: 200, Height: 24 },
3848
customData: meta
3949
} as any);
4050
};
4151
```
4252

43-
N> To configure the server-backed PDF Viewer, set:
44-
`viewer.serviceUrl = 'https://document.syncfusion.com/web-services/pdf-viewer/api/pdfviewer/';`
53+
## Set Default Custom Data for PDF Form Fields Added Using UI
4554

46-
## Set default custom data for UI-created fields
55+
When users add form fields using the [Form Designer toolbar](../toolbar-customization/form-designer-toolbar), you can define default customData so that newly created fields automatically inherit it. Default custom data can be configured using per-field settings objects such as:
4756

48-
When users add fields via the Form Designer toolbar, you can predefine default customData using the per-field settings objects.
57+
- [textFieldSettings](https://ej2.syncfusion.com/documentation/api/pdfviewer/index-default#textfieldsettings)
58+
- [passwordFieldSettings](https://ej2.syncfusion.com/documentation/api/pdfviewer/index-default#passwordfieldsettings)
59+
- [checkBoxFieldSettings](https://ej2.syncfusion.com/documentation/api/pdfviewer/index-default#checkboxfieldsettings)
60+
- [radioButtonFieldSettings](https://ej2.syncfusion.com/documentation/api/pdfviewer/index-default#radiobuttonfieldsettings)
61+
- [listBoxFieldSettings](https://ej2.syncfusion.com/documentation/api/pdfviewer/index-default#listboxfieldsettings)
62+
- [dropDownFieldSettings](https://ej2.syncfusion.com/documentation/api/pdfviewer/index-default#dropdownfieldsettings)
63+
- [signatureFieldSettings](https://ej2.syncfusion.com/documentation/api/pdfviewer/index-default#signaturefieldsettings)
64+
- [initialFieldSettings](https://ej2.syncfusion.com/documentation/api/pdfviewer/index-default#initialfieldsettings)
4965

5066
```ts
51-
// Example: default custom data for all new Textbox fields added from the toolbar
67+
// ...viewer initialization as above...
68+
// Example for texbox defaults
5269
viewer.textFieldSettings = {
5370
name: 'Textbox',
5471
customData: { group: 'contact', createdBy: 'designer', requiredRole: 'user' }
5572
} as any;
56-
```
5773

58-
You can do the same for other field types using passwordFieldSettings, checkBoxFieldSettings, radioButtonFieldSettings, listBoxFieldSettings, dropDownFieldSettings, signatureFieldSettings, and initialFieldSettings.
74+
// Example for checkbox defaults
75+
viewer.checkBoxFieldSettings = {
76+
name: 'Checkbox',
77+
customData: { consentType: 'marketing', defaultChecked: false }
78+
} as any;
79+
```
5980

60-
## Update or replace custom data on existing fields
81+
## Update or Replace PDF Form Field Custom Data
6182

62-
Use updateFormField to set or modify the customData of any existing field (retrieved by object or ID).
83+
You can modify the customData of an existing form field by using the [updateFormField()](https://ej2.syncfusion.com/documentation/api/pdfviewer/index-default#updateformfields) method. The field can be identified using either its object reference or field ID.
6384

6485
```ts
86+
// Retrieve existing fields
6587
const fields = viewer.retrieveFormFields();
66-
const target = fields[0];
67-
viewer.formDesignerModule.updateFormField(target, {
68-
customData: { group: 'profile', flags: ['pii', 'masked'], updatedAt: Date.now() }
69-
} as any);
88+
const target = fields.find((f: any) => f.name === 'Email');
89+
90+
if (target) {
91+
// Merge with existing customData to avoid overwriting
92+
const merged = Object.assign({}, target.customData || {}, { updatedAt: Date.now(), verified: true });
93+
viewer.formDesignerModule.updateFormField(target, { customData: merged } as any);
94+
}
7095
```
7196

72-
Tip: You can merge new values with existing ones in your app code before calling updateFormField.
97+
**Tip:**
98+
Merge new values with the existing customData object before calling [updateFormField()](https://ej2.syncfusion.com/documentation/api/pdfviewer/index-default#updateformfields) to avoid overwriting previously stored data.
7399

74-
## Read custom data
100+
## Read Custom Data from PDF Form Fields
75101

76-
You can read customData from any field at any time. Typical entry points:
77-
- After document load
78-
- On your own UI actions (save, validate, route, etc.)
102+
You can access the customData property from any form field at any point in your application flow, such as:
103+
- After the document is loaded
104+
- During save or submit operations
105+
- While performing validation or conditional routing
79106

80107
```ts
81108
viewer.documentLoad = () => {
82109
const fields = viewer.retrieveFormFields();
83110
fields.forEach((f: any) => {
84-
console.log('Field', f.name, 'customData:', f.customData);
111+
console.log('Field:', f.name, 'customData:', f.customData);
112+
// Example: route based on customData
113+
if (f.customData && f.customData.requiredRole === 'admin') {
114+
// mark field for special handling
115+
}
85116
});
86117
};
87118
```
88119

89-
## Notes and best practices
120+
## Best Practices
90121

91-
- Keep customData small and serializable (plain objects, arrays, numbers, strings, booleans).
92-
- Treat customData as application metadata. Use it to drive business rules, validation, or routing in your app.
93-
- When cloning or copying fields in your UI, also copy or adjust customData as needed.
122+
- Treat customData as application metadata, not display data.
123+
- Use it to drive business rules, validation logic, and workflow decisions.
124+
- Keep the data minimal and structured for easy processing.
125+
- When cloning or copying form fields, ensure customData is copied or updated as required.
94126

95127
[View Sample on GitHub](https://github.com/SyncfusionExamples/typescript-pdf-viewer-examples)
96128

97-
## See also
129+
## See Also
98130

99131
- [Form Designer overview](./overview)
100132
- [Form Designer Toolbar](../toolbar-customization/form-designer-toolbar)
101-
- [Create form fields](./Create-edit-Style-del-formFields/create-formfields)
102-
- [Edit form fields](./Create-edit-Style-del-formFields/edit-formfields)
103-
- [Group form fields](./group-formfields)
104-
- [Form constrain](./form-constrain)
133+
- [Create form fields](./overview-create-forms)
134+
- [Group form fields](../group-formfields)
135+
- [Form flags](./form-constrain)
105136
- [Form validation](./form-validation)
106137
- [Form fields API](./formfields-api)

0 commit comments

Comments
 (0)