1# @ohos.app.form.formBindingData (formBindingData) 2 3The **FormBindingData** module provides APIs for widget data binding. You can use the APIs to create a **FormBindingData** object and obtain related information. 4 5> **NOTE** 6> 7> 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. 8 9## Modules to Import 10 11```ts 12import { formBindingData } from '@kit.FormKit'; 13``` 14 15 16## ProxyData<sup>10+</sup> 17 18Defines the subscription information about the widget update by proxy. 19 20**Model restriction**: This API can be used only in the stage model. 21 22**Atomic service API**: This API can be used in atomic services since API version 11. 23 24**System capability**: SystemCapability.Ability.Form 25 26| Name | Type | Mandatory | Description | 27| -------- | -------- | -------- | -------- | 28| 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.| 29| 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**).| 30 31 32## FormBindingData 33 34Describes a **FormBindingData** object. 35 36**Atomic service API**: This API can be used in atomic services since API version 11. 37 38**System capability**: SystemCapability.Ability.Form 39 40| Name | Type | Mandatory | Description | 41| -------- | -------- | -------- | -------- | 42| 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.| 43| 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>| 44 45## createFormBindingData 46 47createFormBindingData(obj?: Object | string): FormBindingData 48 49Creates a **FormBindingData** object. 50 51**Atomic service API**: This API can be used in atomic services since API version 11. 52 53**System capability**: SystemCapability.Ability.Form 54 55**Parameters** 56 57| Name | Type | Mandatory | Description | 58| ------ | -------------- | ---- | ------------------------------------------------------------ | 59| 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}}.| 60 61 62**Return value** 63 64| Type | Description | 65| ----------------------------------- | --------------------------------------- | 66| [FormBindingData](#formbindingdata) | **FormBindingData** object created based on the passed data. | 67 68**Error codes** 69 70| ID | Error Message | 71| -------- | -------- | 72| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed | 73 74For details about the error codes, see [Form Error Codes](errorcode-form.md). 75 76 77**Example** 78 79```ts 80import { formBindingData } from '@kit.FormKit'; 81import { BusinessError } from '@kit.BasicServicesKit'; 82import { fileIo } from '@kit.CoreFileKit'; 83 84try { 85 let file = fileIo.openSync('/path/to/form.png'); 86 let formImagesParam: Record<string, number> = { 87 'image': file.fd 88 }; 89 let createFormBindingDataParam: Record<string, string | Object> = { 90 'name': '21°', 91 'imgSrc': 'image', 92 'formImages': formImagesParam 93 }; 94 95 formBindingData.createFormBindingData(createFormBindingDataParam); 96} catch (error) { 97 let code = (error as BusinessError).code; 98 let message = (error as BusinessError).message; 99 console.error(`catch error, code: ${code}, message: ${message}`); 100} 101``` 102