1e41f4b71Sopenharmony_ci# Updating Widget Content Through the message Event 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciOn the widget page, the [postCardAction](../reference/apis-arkui/js-apis-postCardAction.md#postcardaction) API can be used to trigger a message event to start a FormExtensionAbility, which then updates the widget content. The following is an example of this widget update mode. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **NOTE** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> This topic describes development for dynamic widgets. For static widgets, see [FormLink](../reference/apis-arkui/arkui-ts/ts-container-formlink.md). 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci- On the widget page, register the **onClick** event callback of the button and call the **postCardAction** API in the callback to trigger the message event to start the FormExtensionAbility. Use [LocalStorageProp](../quick-start/arkts-localstorage.md#localstorageprop) to decorate the widget data to be updated. 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci ```ts 12e41f4b71Sopenharmony_ci let storageUpdateByMsg = new LocalStorage(); 13e41f4b71Sopenharmony_ci 14e41f4b71Sopenharmony_ci @Entry(storageUpdateByMsg) 15e41f4b71Sopenharmony_ci @Component 16e41f4b71Sopenharmony_ci struct UpdateByMessageCard { 17e41f4b71Sopenharmony_ci @LocalStorageProp('title') title: ResourceStr = $r('app.string.default_title'); 18e41f4b71Sopenharmony_ci @LocalStorageProp('detail') detail: ResourceStr = $r('app.string.DescriptionDefault'); 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_ci build() { 21e41f4b71Sopenharmony_ci Column() { 22e41f4b71Sopenharmony_ci Column() { 23e41f4b71Sopenharmony_ci Text(this.title) 24e41f4b71Sopenharmony_ci .fontColor('#FFFFFF') 25e41f4b71Sopenharmony_ci .opacity(0.9) 26e41f4b71Sopenharmony_ci .fontSize(14) 27e41f4b71Sopenharmony_ci .margin({ top: '8%', left: '10%' }) 28e41f4b71Sopenharmony_ci Text(this.detail) 29e41f4b71Sopenharmony_ci .fontColor('#FFFFFF') 30e41f4b71Sopenharmony_ci .opacity(0.6) 31e41f4b71Sopenharmony_ci .fontSize(12) 32e41f4b71Sopenharmony_ci .margin({ top: '5%', left: '10%' }) 33e41f4b71Sopenharmony_ci }.width('100%').height('50%') 34e41f4b71Sopenharmony_ci .alignItems(HorizontalAlign.Start) 35e41f4b71Sopenharmony_ci 36e41f4b71Sopenharmony_ci Row() { 37e41f4b71Sopenharmony_ci Button() { 38e41f4b71Sopenharmony_ci Text($r('app.string.update')) 39e41f4b71Sopenharmony_ci .fontColor('#45A6F4') 40e41f4b71Sopenharmony_ci .fontSize(12) 41e41f4b71Sopenharmony_ci } 42e41f4b71Sopenharmony_ci .width(120) 43e41f4b71Sopenharmony_ci .height(32) 44e41f4b71Sopenharmony_ci .margin({ top: '30%', bottom: '10%' }) 45e41f4b71Sopenharmony_ci .backgroundColor('#FFFFFF') 46e41f4b71Sopenharmony_ci .borderRadius(16) 47e41f4b71Sopenharmony_ci .onClick(() => { 48e41f4b71Sopenharmony_ci postCardAction(this, { 49e41f4b71Sopenharmony_ci action: 'message', 50e41f4b71Sopenharmony_ci params: { msgTest: 'messageEvent' } 51e41f4b71Sopenharmony_ci }); 52e41f4b71Sopenharmony_ci }) 53e41f4b71Sopenharmony_ci }.width('100%').height('40%') 54e41f4b71Sopenharmony_ci .justifyContent(FlexAlign.Center) 55e41f4b71Sopenharmony_ci } 56e41f4b71Sopenharmony_ci .width('100%') 57e41f4b71Sopenharmony_ci .height('100%') 58e41f4b71Sopenharmony_ci .alignItems(HorizontalAlign.Start) 59e41f4b71Sopenharmony_ci .backgroundImage($r('app.media.CardEvent')) 60e41f4b71Sopenharmony_ci .backgroundImageSize(ImageSize.Cover) 61e41f4b71Sopenharmony_ci } 62e41f4b71Sopenharmony_ci } 63e41f4b71Sopenharmony_ci ``` 64e41f4b71Sopenharmony_ci 65e41f4b71Sopenharmony_ci- Call the [updateForm](../reference/apis-form-kit/js-apis-app-form-formProvider.md#updateform) API to update the widget in the **onFormEvent** callback of the FormExtensionAbility. 66e41f4b71Sopenharmony_ci 67e41f4b71Sopenharmony_ci ```ts 68e41f4b71Sopenharmony_ci import { BusinessError } from '@kit.BasicServicesKit'; 69e41f4b71Sopenharmony_ci import { formBindingData, FormExtensionAbility, formProvider } from '@kit.FormKit'; 70e41f4b71Sopenharmony_ci import { hilog } from '@kit.PerformanceAnalysisKit'; 71e41f4b71Sopenharmony_ci 72e41f4b71Sopenharmony_ci const TAG: string = 'EntryFormAbility'; 73e41f4b71Sopenharmony_ci const DOMAIN_NUMBER: number = 0xFF00; 74e41f4b71Sopenharmony_ci 75e41f4b71Sopenharmony_ci export default class EntryFormAbility extends FormExtensionAbility { 76e41f4b71Sopenharmony_ci onFormEvent(formId: string, message: string): void { 77e41f4b71Sopenharmony_ci // Called when a specified message event defined by the form provider is triggered. 78e41f4b71Sopenharmony_ci hilog.info(DOMAIN_NUMBER, TAG, `FormAbility onFormEvent, formId = ${formId}, message: ${JSON.stringify(message)}`); 79e41f4b71Sopenharmony_ci 80e41f4b71Sopenharmony_ci class FormDataClass { 81e41f4b71Sopenharmony_ci title: string ='Title Update.'; // It matches the widget layout. 82e41f4b71Sopenharmony_ci detail: string = 'Description update success.'; // It matches the widget layout. 83e41f4b71Sopenharmony_ci } 84e41f4b71Sopenharmony_ci 85e41f4b71Sopenharmony_ci let formData = new FormDataClass(); 86e41f4b71Sopenharmony_ci let formInfo: formBindingData.FormBindingData = formBindingData.createFormBindingData(formData); 87e41f4b71Sopenharmony_ci formProvider.updateForm(formId, formInfo).then(() => { 88e41f4b71Sopenharmony_ci hilog.info(DOMAIN_NUMBER, TAG, 'FormAbility updateForm success.'); 89e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 90e41f4b71Sopenharmony_ci hilog.info(DOMAIN_NUMBER, TAG, `Operation updateForm failed. Cause: ${JSON.stringify(error)}`); 91e41f4b71Sopenharmony_ci }) 92e41f4b71Sopenharmony_ci } 93e41f4b71Sopenharmony_ci //... 94e41f4b71Sopenharmony_ci } 95e41f4b71Sopenharmony_ci ``` 96e41f4b71Sopenharmony_ci 97e41f4b71Sopenharmony_ci The figure below shows the effect. 98e41f4b71Sopenharmony_ci 99e41f4b71Sopenharmony_ci | Initial State | After Clicking | 100e41f4b71Sopenharmony_ci | ------------------------------------------------------- | ----------------------------------------------------- | 101e41f4b71Sopenharmony_ci |  |  | 102