1e41f4b71Sopenharmony_ci# @ohos.app.form.formBindingData (formBindingData)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciThe **FormBindingData** module provides APIs for widget data binding. You can use the APIs to create a **FormBindingData** object and obtain related information.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci> **NOTE**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci## Modules to Import
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci```ts
12e41f4b71Sopenharmony_ciimport { formBindingData } from '@kit.FormKit';
13e41f4b71Sopenharmony_ci```
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci
16e41f4b71Sopenharmony_ci## ProxyData<sup>10+</sup>
17e41f4b71Sopenharmony_ci
18e41f4b71Sopenharmony_ciDefines the subscription information about the widget update by proxy.
19e41f4b71Sopenharmony_ci
20e41f4b71Sopenharmony_ci**Model restriction**: This API can be used only in the stage model.
21e41f4b71Sopenharmony_ci
22e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
23e41f4b71Sopenharmony_ci
24e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.Form
25e41f4b71Sopenharmony_ci
26e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description |
27e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- |
28e41f4b71Sopenharmony_ci| key<sup>10+</sup> | string | Yes | Subscriber ID of the widget update by proxy. The value is the same as that of the data publisher.|
29e41f4b71Sopenharmony_ci| subscriberId<sup>10+</sup> | string | No | Subscription condition of the widget update by proxy. The default value is the current widget ID (specified by **formId**).|
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ci
32e41f4b71Sopenharmony_ci## FormBindingData
33e41f4b71Sopenharmony_ci
34e41f4b71Sopenharmony_ciDescribes a **FormBindingData** object.
35e41f4b71Sopenharmony_ci
36e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
37e41f4b71Sopenharmony_ci
38e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.Form
39e41f4b71Sopenharmony_ci
40e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description |
41e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- |
42e41f4b71Sopenharmony_ci| data | Object | Yes | Data to be displayed on the widget. The value can be an object containing multiple key-value pairs or a string in JSON format.|
43e41f4b71Sopenharmony_ci| proxies<sup>10+</sup> | Array<[ProxyData](#proxydata10)> | No | Subscription information of the widget update by proxy. The default value is an empty array.<br>**Model restriction**: This API can be used only in the stage model.<br>|
44e41f4b71Sopenharmony_ci
45e41f4b71Sopenharmony_ci## createFormBindingData
46e41f4b71Sopenharmony_ci
47e41f4b71Sopenharmony_cicreateFormBindingData(obj?: Object | string): FormBindingData
48e41f4b71Sopenharmony_ci
49e41f4b71Sopenharmony_ciCreates a **FormBindingData** object.
50e41f4b71Sopenharmony_ci
51e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
52e41f4b71Sopenharmony_ci
53e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.Form
54e41f4b71Sopenharmony_ci
55e41f4b71Sopenharmony_ci**Parameters**
56e41f4b71Sopenharmony_ci
57e41f4b71Sopenharmony_ci| Name | Type          | Mandatory | Description                                                        |
58e41f4b71Sopenharmony_ci| ------ | -------------- | ---- | ------------------------------------------------------------ |
59e41f4b71Sopenharmony_ci| obj    | Object\|string | No  | Data to be displayed on the widget. The value can be an object containing multiple key-value pairs or a string in JSON format. The image data is identified by **'formImages'**, and the content is multiple key-value pairs, each of which consists of an image identifier and image file descriptor. The final format is {'formImages': {'key1': fd1, 'key2': fd2}}.|
60e41f4b71Sopenharmony_ci
61e41f4b71Sopenharmony_ci
62e41f4b71Sopenharmony_ci**Return value**
63e41f4b71Sopenharmony_ci
64e41f4b71Sopenharmony_ci| Type                               | Description                                   |
65e41f4b71Sopenharmony_ci| ----------------------------------- | --------------------------------------- |
66e41f4b71Sopenharmony_ci| [FormBindingData](#formbindingdata) | **FormBindingData** object created based on the passed data. |
67e41f4b71Sopenharmony_ci
68e41f4b71Sopenharmony_ci**Error codes**
69e41f4b71Sopenharmony_ci
70e41f4b71Sopenharmony_ci| ID | Error Message |
71e41f4b71Sopenharmony_ci| -------- | -------- |
72e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed |
73e41f4b71Sopenharmony_ci
74e41f4b71Sopenharmony_ciFor details about the error codes, see [Form Error Codes](errorcode-form.md).
75e41f4b71Sopenharmony_ci
76e41f4b71Sopenharmony_ci
77e41f4b71Sopenharmony_ci**Example**
78e41f4b71Sopenharmony_ci
79e41f4b71Sopenharmony_ci```ts
80e41f4b71Sopenharmony_ciimport { formBindingData } from '@kit.FormKit';
81e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
82e41f4b71Sopenharmony_ciimport { fileIo } from '@kit.CoreFileKit';
83e41f4b71Sopenharmony_ci
84e41f4b71Sopenharmony_citry {
85e41f4b71Sopenharmony_ci  let file = fileIo.openSync('/path/to/form.png');
86e41f4b71Sopenharmony_ci  let formImagesParam: Record<string, number> = {
87e41f4b71Sopenharmony_ci    'image': file.fd
88e41f4b71Sopenharmony_ci  };
89e41f4b71Sopenharmony_ci  let createFormBindingDataParam: Record<string, string | Object> = {
90e41f4b71Sopenharmony_ci    'name': '21°',
91e41f4b71Sopenharmony_ci    'imgSrc': 'image',
92e41f4b71Sopenharmony_ci    'formImages': formImagesParam
93e41f4b71Sopenharmony_ci  };
94e41f4b71Sopenharmony_ci
95e41f4b71Sopenharmony_ci  formBindingData.createFormBindingData(createFormBindingDataParam);
96e41f4b71Sopenharmony_ci} catch (error) {
97e41f4b71Sopenharmony_ci  let code = (error as BusinessError).code;
98e41f4b71Sopenharmony_ci  let message = (error as BusinessError).message;
99e41f4b71Sopenharmony_ci  console.error(`catch error, code: ${code}, message: ${message}`);
100e41f4b71Sopenharmony_ci}
101e41f4b71Sopenharmony_ci```
102