1e41f4b71Sopenharmony_ci# FormComponent (System API)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciThe **FormComponent** is used to display widgets.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci>  **NOTE**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci> - This component is supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8e41f4b71Sopenharmony_ci>
9e41f4b71Sopenharmony_ci> - This component is intended for the widget host. For details about the widget provider, see [JS Service Widget UI Components](../js-service-widget-ui/js-service-widget-file.md).
10e41f4b71Sopenharmony_ci>
11e41f4b71Sopenharmony_ci> - To use this component, you must have the system signature.
12e41f4b71Sopenharmony_ci>
13e41f4b71Sopenharmony_ci> - The APIs provided by this module are system APIs.
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci## Required Permissions
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ciohos.permission.REQUIRE_FORM, ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ci
20e41f4b71Sopenharmony_ci## Child Components
21e41f4b71Sopenharmony_ci
22e41f4b71Sopenharmony_ciNot supported
23e41f4b71Sopenharmony_ci
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci## APIs
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ciFormComponent (value: FormInfo)
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ciCreates a **FormComponent** instance to display the provided widget.
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ci**Parameters**
32e41f4b71Sopenharmony_ci
33e41f4b71Sopenharmony_ci| Name   | Type                       | Mandatory | Description                                                               |
34e41f4b71Sopenharmony_ci| --------- | ------------------------------- | ---- | ----------------------------------------------------------------------- |
35e41f4b71Sopenharmony_ci| value        | [FormInfo](#forminfo12)                 | Yes  | Widget information.  |
36e41f4b71Sopenharmony_ci
37e41f4b71Sopenharmony_ci## FormInfo<sup>12+</sup>
38e41f4b71Sopenharmony_ci
39e41f4b71Sopenharmony_ciProvides the widget information.
40e41f4b71Sopenharmony_ci
41e41f4b71Sopenharmony_ci| Name   | Type                       | Mandatory | Description                                                               |
42e41f4b71Sopenharmony_ci| --------- | ------------------------------- | ---- |-------|
43e41f4b71Sopenharmony_ci| id        | number \| string                    | Yes  | Widget ID. Set this parameter to **0** for a new widget.<br>**NOTE**<br>Different widget hosts cannot use the same ID.<br>If a widget host uses the same ID for two widgets, the one added later is displayed.                                       |
44e41f4b71Sopenharmony_ci| name      | string                          | Yes  | Widget name.                                                             |
45e41f4b71Sopenharmony_ci| bundle    | string                          | Yes  | Bundle name of the widget.                                                         |
46e41f4b71Sopenharmony_ci| ability   | string                          | Yes  | Ability name of the widget.                                                  |
47e41f4b71Sopenharmony_ci| module    | string                          | Yes  | Module name of the widget.                                                         |
48e41f4b71Sopenharmony_ci| dimension | [FormDimension](#formdimension) | No  | Dimensions of the widget. The widgets in the 2 x 2, 4 x 4, and 4 x 2 dimensions are supported.<br>Default value: **Dimension_2_2** |
49e41f4b71Sopenharmony_ci| temporary | boolean                         | No  | Whether the widget is a temporary one.                                                   |
50e41f4b71Sopenharmony_ci| renderingMode | [FormRenderingMode](#formrenderingmode11) | No  | Widget rendering mode. The options are as follows:<br>- **FULL_COLOR** (default): full color mode, where the widget framework does not change the widget effect, which means that the widget is displayed in the effect as you set it.<br>- **SINGLE_COLOR**: single color mode, where the widget framework sets the widget background to transparent. In this mode you need to set the widget style based on the best practices.<br>**NOTE**<br>If the system does not support unified rendering, the widget framework does not set the widget background to transparent in single color mode. |
51e41f4b71Sopenharmony_ci
52e41f4b71Sopenharmony_ci## FormCallbackInfo<sup>12+</sup>
53e41f4b71Sopenharmony_ci
54e41f4b71Sopenharmony_ciRepresents the parameters for obtaining a widget ID (**formId**) when querying or uninstalling a widget.
55e41f4b71Sopenharmony_ci
56e41f4b71Sopenharmony_ci| Name   | Type                       | Mandatory | Description                                                               |
57e41f4b71Sopenharmony_ci| --------- | ------------------------------- | ---- | ----------------------------------------------------------------------- |
58e41f4b71Sopenharmony_ci| id        | number                 | Yes  | Widget ID of the number type.<br>**NOTE**<br>If the obtained ID is **-1**, the ID is greater than or equal to 2^53. In this case, you need to use **idString** to obtain the ID.                                       |
59e41f4b71Sopenharmony_ci| idString      | string                          | Yes  | Widget ID of the string type.<br>                                                             |
60e41f4b71Sopenharmony_ci
61e41f4b71Sopenharmony_ci## FormDimension
62e41f4b71Sopenharmony_ci
63e41f4b71Sopenharmony_ci| Name                      | Description    |
64e41f4b71Sopenharmony_ci| -------------------------- | -------- |
65e41f4b71Sopenharmony_ci| Dimension_1_2              | 1 x 2 widget. |
66e41f4b71Sopenharmony_ci| Dimension_2_2              | 2 x 2 widget. |
67e41f4b71Sopenharmony_ci| Dimension_2_4              | 2 x 4 widget. |
68e41f4b71Sopenharmony_ci| Dimension_4_4              | 4 x 4 widget. |
69e41f4b71Sopenharmony_ci| Dimension_2_1<sup>9+</sup> | 2 x 1 widget. |
70e41f4b71Sopenharmony_ci| Dimension_1_1<sup>11+</sup> | 1 x 1 widget. |
71e41f4b71Sopenharmony_ci| Dimension_6_4<sup>12+</sup> | 6 x 4 widget. |
72e41f4b71Sopenharmony_ci
73e41f4b71Sopenharmony_ci## FormRenderingMode<sup>11+</sup>
74e41f4b71Sopenharmony_ci| Name                      | Description    |
75e41f4b71Sopenharmony_ci| -------------------------- | -------- |
76e41f4b71Sopenharmony_ci| FULL_COLOR                 | Full color mode.|
77e41f4b71Sopenharmony_ci| SINGLE_COLOR               | Single color mode.|
78e41f4b71Sopenharmony_ci
79e41f4b71Sopenharmony_ci## Attributes
80e41f4b71Sopenharmony_ci
81e41f4b71Sopenharmony_ci### size
82e41f4b71Sopenharmony_ci
83e41f4b71Sopenharmony_cisize(value: { width: number; height: number })
84e41f4b71Sopenharmony_ci
85e41f4b71Sopenharmony_ciSets the size for the widget.
86e41f4b71Sopenharmony_ci
87e41f4b71Sopenharmony_ci**System API**: This is a system API.
88e41f4b71Sopenharmony_ci
89e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
90e41f4b71Sopenharmony_ci
91e41f4b71Sopenharmony_ci**Parameters** 
92e41f4b71Sopenharmony_ci
93e41f4b71Sopenharmony_ci| Name | Type                                                     | Mandatory | Description      |
94e41f4b71Sopenharmony_ci| ------ | --------------------------------------------------------- | ---- | ---------- |
95e41f4b71Sopenharmony_ci| value  | {<br>width?: number,<br>height?: number<br>} | Yes  | Width and height. |
96e41f4b71Sopenharmony_ci
97e41f4b71Sopenharmony_ci### moduleName
98e41f4b71Sopenharmony_ci
99e41f4b71Sopenharmony_cimoduleName(value: string)
100e41f4b71Sopenharmony_ci
101e41f4b71Sopenharmony_ciSets the module name for the widget.
102e41f4b71Sopenharmony_ci
103e41f4b71Sopenharmony_ci**System API**: This is a system API.
104e41f4b71Sopenharmony_ci
105e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
106e41f4b71Sopenharmony_ci
107e41f4b71Sopenharmony_ci**Parameters** 
108e41f4b71Sopenharmony_ci
109e41f4b71Sopenharmony_ci| Name | Type  | Mandatory | Description          |
110e41f4b71Sopenharmony_ci| ------ | ------ | ---- | -------------- |
111e41f4b71Sopenharmony_ci| value  | string | Yes  | Module name of the widget. |
112e41f4b71Sopenharmony_ci
113e41f4b71Sopenharmony_ci### dimension
114e41f4b71Sopenharmony_ci
115e41f4b71Sopenharmony_cidimension(value: FormDimension)
116e41f4b71Sopenharmony_ci
117e41f4b71Sopenharmony_ciSets the dimensions for the widget. The 2 x 2, 4 x 4, and 4 x 2 options are available.
118e41f4b71Sopenharmony_ci
119e41f4b71Sopenharmony_ci**System API**: This is a system API.
120e41f4b71Sopenharmony_ci
121e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
122e41f4b71Sopenharmony_ci
123e41f4b71Sopenharmony_ci**Parameters** 
124e41f4b71Sopenharmony_ci
125e41f4b71Sopenharmony_ci| Name | Type                           | Mandatory | Description                                |
126e41f4b71Sopenharmony_ci| ------ | ------------------------------- | ---- | ------------------------------------ |
127e41f4b71Sopenharmony_ci| value  | [FormDimension](#formdimension) | Yes  | Dimensions of the widget.<br>Default value: **Dimension_2_2** |
128e41f4b71Sopenharmony_ci
129e41f4b71Sopenharmony_ci### allowUpdate
130e41f4b71Sopenharmony_ci
131e41f4b71Sopenharmony_ciallowUpdate(value: boolean)
132e41f4b71Sopenharmony_ci
133e41f4b71Sopenharmony_ciSets whether to allow the widget to update.
134e41f4b71Sopenharmony_ci
135e41f4b71Sopenharmony_ci**System API**: This is a system API.
136e41f4b71Sopenharmony_ci
137e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
138e41f4b71Sopenharmony_ci
139e41f4b71Sopenharmony_ci**Parameters** 
140e41f4b71Sopenharmony_ci
141e41f4b71Sopenharmony_ci| Name | Type   | Mandatory | Description                               |
142e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ----------------------------------- |
143e41f4b71Sopenharmony_ci| value  | boolean | Yes  | Whether to allow the widget to update.<br>Default value: **true** |
144e41f4b71Sopenharmony_ci
145e41f4b71Sopenharmony_ci### visibility
146e41f4b71Sopenharmony_ci
147e41f4b71Sopenharmony_civisibility(value: Visibility)
148e41f4b71Sopenharmony_ci
149e41f4b71Sopenharmony_ciSets whether the widget is visible.
150e41f4b71Sopenharmony_ci
151e41f4b71Sopenharmony_ci**System API**: This is a system API.
152e41f4b71Sopenharmony_ci
153e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
154e41f4b71Sopenharmony_ci
155e41f4b71Sopenharmony_ci**Parameters** 
156e41f4b71Sopenharmony_ci
157e41f4b71Sopenharmony_ci| Name | Type                                         | Mandatory | Description                                  |
158e41f4b71Sopenharmony_ci| ------ | --------------------------------------------- | ---- | -------------------------------------- |
159e41f4b71Sopenharmony_ci| value  | [Visibility](ts-appendix-enums.md#visibility) | Yes  | Whether the widget is visible.<br>Default value: **Visible** |
160e41f4b71Sopenharmony_ci
161e41f4b71Sopenharmony_ci## Events
162e41f4b71Sopenharmony_ci
163e41f4b71Sopenharmony_ci### onAcquired
164e41f4b71Sopenharmony_ci
165e41f4b71Sopenharmony_cionAcquired(callback: Callback[\<FormCallbackInfo>](#formcallbackinfo12)): FormComponentAttribute
166e41f4b71Sopenharmony_ci
167e41f4b71Sopenharmony_ciCalled when the widget is obtained.
168e41f4b71Sopenharmony_ci
169e41f4b71Sopenharmony_ci**System API**: This is a system API.
170e41f4b71Sopenharmony_ci
171e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
172e41f4b71Sopenharmony_ci
173e41f4b71Sopenharmony_ci**Parameters** 
174e41f4b71Sopenharmony_ci
175e41f4b71Sopenharmony_ci| Name | Type                               | Mandatory | Description      |
176e41f4b71Sopenharmony_ci| ------ | ----------------------------------- | ---- | ---------- |
177e41f4b71Sopenharmony_ci| Callback | [FormCallbackInfo](#formcallbackinfo12) | Yes  | Widget ID. |
178e41f4b71Sopenharmony_ci
179e41f4b71Sopenharmony_ci### onError
180e41f4b71Sopenharmony_ci
181e41f4b71Sopenharmony_cionError(callback: (info: { errcode: number; msg: string }) => void)
182e41f4b71Sopenharmony_ci
183e41f4b71Sopenharmony_ciCalled when an error occurs during component loading.
184e41f4b71Sopenharmony_ci
185e41f4b71Sopenharmony_ci**System API**: This is a system API.
186e41f4b71Sopenharmony_ci
187e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
188e41f4b71Sopenharmony_ci
189e41f4b71Sopenharmony_ci**Parameters** 
190e41f4b71Sopenharmony_ci
191e41f4b71Sopenharmony_ci| Name | Type                                                        | Mandatory | Description                                           |
192e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | ----------------------------------------------- |
193e41f4b71Sopenharmony_ci| info   |  { errcode: number, msg: string } | Yes  | **errcode**: error code.<br>**msg**: error information. |
194e41f4b71Sopenharmony_ci
195e41f4b71Sopenharmony_ci### onRouter
196e41f4b71Sopenharmony_ci
197e41f4b71Sopenharmony_cionRouter(callback: (info: any) =&gt; void)
198e41f4b71Sopenharmony_ci
199e41f4b71Sopenharmony_ciCalled when routing occurs for the widget. This API returns information in [routerEvent](../js-service-widget-ui/js-service-widget-syntax-hml.md#event-binding).
200e41f4b71Sopenharmony_ci
201e41f4b71Sopenharmony_ci**System API**: This is a system API.
202e41f4b71Sopenharmony_ci
203e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
204e41f4b71Sopenharmony_ci
205e41f4b71Sopenharmony_ci**Parameters** 
206e41f4b71Sopenharmony_ci
207e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description                                                        |
208e41f4b71Sopenharmony_ci| ------ | ---- | ---- | ------------------------------------------------------------ |
209e41f4b71Sopenharmony_ci| info   | any  | Yes  | Information in [routerEvent](../js-service-widget-ui/js-service-widget-syntax-hml.md#event-binding). |
210e41f4b71Sopenharmony_ci
211e41f4b71Sopenharmony_ci### onUninstall
212e41f4b71Sopenharmony_ci
213e41f4b71Sopenharmony_cionUninstall(callback: Callback[\<FormCallbackInfo>](#formcallbackinfo12)): FormComponentAttribute
214e41f4b71Sopenharmony_ci
215e41f4b71Sopenharmony_ciCalled when the widget is uninstalled. This API returns the ID of the uninstalled widget.
216e41f4b71Sopenharmony_ci
217e41f4b71Sopenharmony_ci**System API**: This is a system API.
218e41f4b71Sopenharmony_ci
219e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
220e41f4b71Sopenharmony_ci
221e41f4b71Sopenharmony_ci**Parameters** 
222e41f4b71Sopenharmony_ci
223e41f4b71Sopenharmony_ci| Name | Type                               | Mandatory | Description      |
224e41f4b71Sopenharmony_ci| ------ | ----------------------------------- | ---- | ---------- |
225e41f4b71Sopenharmony_ci| Callback   | [FormCallbackInfo](#formcallbackinfo12) | Yes  | Widget ID. |
226e41f4b71Sopenharmony_ci
227e41f4b71Sopenharmony_ci
228e41f4b71Sopenharmony_ci## Example
229e41f4b71Sopenharmony_ci
230e41f4b71Sopenharmony_ci 
231e41f4b71Sopenharmony_ci
232e41f4b71Sopenharmony_ciThis example creates a 2 x 2 widget and registers event callbacks.
233e41f4b71Sopenharmony_ci```ts
234e41f4b71Sopenharmony_ci//card.ets
235e41f4b71Sopenharmony_ci@Entry
236e41f4b71Sopenharmony_ci@Component
237e41f4b71Sopenharmony_cistruct CardExample {
238e41f4b71Sopenharmony_ci  @State formId:string = '0';
239e41f4b71Sopenharmony_ci  build() {
240e41f4b71Sopenharmony_ci    Column() {
241e41f4b71Sopenharmony_ci      Text('this is a card')
242e41f4b71Sopenharmony_ci        .fontSize(50)
243e41f4b71Sopenharmony_ci        .fontWeight(FontWeight.Bold)
244e41f4b71Sopenharmony_ci      FormComponent({
245e41f4b71Sopenharmony_ci        id:this.formId,
246e41f4b71Sopenharmony_ci        name:"Form1",
247e41f4b71Sopenharmony_ci        bundle:"com.example.cardexample",
248e41f4b71Sopenharmony_ci        ability:"FormAbility",
249e41f4b71Sopenharmony_ci        module:"entry",
250e41f4b71Sopenharmony_ci        dimension:FormDimension.Dimension_2_2,
251e41f4b71Sopenharmony_ci        temporary:false
252e41f4b71Sopenharmony_ci      })
253e41f4b71Sopenharmony_ci        .allowUpdate(true)
254e41f4b71Sopenharmony_ci        .size({width:360,height:360})
255e41f4b71Sopenharmony_ci        .visibility(Visibility.Visible)
256e41f4b71Sopenharmony_ci        .onAcquired((form: FormCallbackInfo)=>{
257e41f4b71Sopenharmony_ci          console.log(`form info : ${JSON.stringify(form)}`);
258e41f4b71Sopenharmony_ci          // Invalid form id
259e41f4b71Sopenharmony_ci          if (form.id == -1) {
260e41f4b71Sopenharmony_ci            this.formId = form.idString;
261e41f4b71Sopenharmony_ci          } else {
262e41f4b71Sopenharmony_ci            this.formId = form.id.toString();
263e41f4b71Sopenharmony_ci          }
264e41f4b71Sopenharmony_ci        })
265e41f4b71Sopenharmony_ci        .onError((err)=>{
266e41f4b71Sopenharmony_ci          console.log(`fail to add form, err: ${JSON.stringify(err)}`);
267e41f4b71Sopenharmony_ci        })
268e41f4b71Sopenharmony_ci        .onUninstall((form: FormCallbackInfo)=>{
269e41f4b71Sopenharmony_ci          console.log(`uninstall form success : ${JSON.stringify(form)}`);
270e41f4b71Sopenharmony_ci          // Invalid form id
271e41f4b71Sopenharmony_ci          if (form.id == -1) {
272e41f4b71Sopenharmony_ci            this.formId = form.idString;
273e41f4b71Sopenharmony_ci          } else {
274e41f4b71Sopenharmony_ci            this.formId = form.id.toString();
275e41f4b71Sopenharmony_ci          }
276e41f4b71Sopenharmony_ci        })
277e41f4b71Sopenharmony_ci    }
278e41f4b71Sopenharmony_ci    .width('100%')
279e41f4b71Sopenharmony_ci    .height('100%')
280e41f4b71Sopenharmony_ci  }
281e41f4b71Sopenharmony_ci}
282e41f4b71Sopenharmony_ci```
283e41f4b71Sopenharmony_ci
284e41f4b71Sopenharmony_ci![Form](figures/form.png)
285