1# @ohos.app.form.FormExtensionAbility (FormExtensionAbility) (System API) 2 3The **FormExtensionAbility** module provides lifecycle callbacks invoked when a widget is created, destroyed, or updated. 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> The APIs of this module can be used only in the stage model. 9> This topic describes only system APIs provided by the module. For details about its public APIs, see [@ohos.app.form.FormExtensionAbility (FormExtensionAbility)](./js-apis-app-form-formExtensionAbility.md). 10 11## Modules to Import 12 13```ts 14import { FormExtensionAbility } from '@kit.FormKit'; 15``` 16 17## onShareForm 18 19onShareForm?(formId: string): Record\<string, Object> 20 21Called to notify the widget provider that the widget host is sharing the widget data. 22 23**System capability**: SystemCapability.Ability.Form 24 25**System API**: This is a system API. 26 27**Parameters** 28 29| Name| Type| Mandatory| Description| 30| -------- | -------- | -------- | -------- | 31| formId | string | Yes| Widget ID.| 32 33**Return value** 34 35| Type | Description | 36| ---------------------- | -------------------------------------------- | 37| Record\<string, Object> | Data to be shared by the widget, in the form of key-value pairs.| 38 39**Example** 40 41```ts 42import { FormExtensionAbility } from '@kit.FormKit'; 43 44export default class MyFormExtensionAbility extends FormExtensionAbility { 45 onShareForm(formId: string) { 46 console.log(`FormExtensionAbility onShareForm, formId: ${formId}`); 47 let wantParams: Record<string, Object> = { 48 'temperature': '20', 49 'time': '2022-8-8 09:59', 50 }; 51 return wantParams; 52 } 53}; 54``` 55 56## onAcquireFormData<sup>10+<sup> 57 58onAcquireFormData?(formId: string): Record\<string, Object> 59 60Called to notify the widget provider that the widget host is requesting the custom data. 61 62**System capability**: SystemCapability.Ability.Form 63 64**System API**: This is a system API. 65 66**Parameters** 67 68| Name| Type| Mandatory| Description| 69| -------- | -------- | -------- | -------- | 70| formId | string | Yes| Widget ID.| 71 72**Return value** 73 74| Type | Description | 75| ---------------------- | -------------------------------------------- | 76| Record\<string, Object> | Custom data of the widget, in the form of key-value pairs.| 77 78**Example** 79 80```ts 81import { FormExtensionAbility } from '@kit.FormKit'; 82 83export default class MyFormExtensionAbility extends FormExtensionAbility { 84 onAcquireFormData(formId: string) { 85 console.log(`FormExtensionAbility onAcquireFormData, formId: ${formId}`); 86 let wantParams: Record<string, Object> = { 87 'temperature': '20', 88 'time': '2022-8-8 09:59', 89 }; 90 return wantParams; 91 } 92}; 93``` 94