js-apis-formprovider.md 4.9 KB
Newer Older
W
wusongqing 已提交
1 2
# FormProvider

W
wusongqing 已提交
3 4
> **NOTE**
>
W
wusongqing 已提交
5 6
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.

W
wusongqing 已提交
7
Provides APIs related to the widget provider.
W
wusongqing 已提交
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

## Modules to Import

```
import formProvider from '@ohos.application.formProvider';
```

## Required Permissions

None.

## setFormNextRefreshTime

setFormNextRefreshTime(formId: string, minute: number, callback: AsyncCallback<void>): void;

W
wusongqing 已提交
23
Sets the next refresh time for a widget. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
24 25 26 27 28 29 30

**System capability**

SystemCapability.Ability.Form

**Parameters**

W
wusongqing 已提交
31 32 33 34 35
| Name| Type   | Mandatory| Description                                  |
| ------ | ------ | ---- | ------------------------------------- |
| formId | string | Yes  | ID of a widget.                              |
| minute | number | Yes  | Refresh interval, in minutes. The value must be greater than or equal to 5.    |
| callback | AsyncCallback<void> | Yes| Callback used to return the result.|
W
wusongqing 已提交
36 37 38 39 40 41

**Example**

  ```js
  var formId = "12400633174999288";
  formProvider.setFormNextRefreshTime(formId, 5, (error, data) => {
42 43
      if (error.code) {
          console.log('formProvider setFormNextRefreshTime, error:' + JSON.stringify(error));
W
wusongqing 已提交
44 45 46 47 48 49 50 51
      }
  });
  ```

## setFormNextRefreshTime

setFormNextRefreshTime(formId: string, minute: number): Promise<void>;

W
wusongqing 已提交
52
Sets the next refresh time for a widget. This API uses a promise to return the result.
W
wusongqing 已提交
53 54 55 56 57 58 59

**System capability**

SystemCapability.Ability.Form

**Parameters**

W
wusongqing 已提交
60 61 62 63
| Name| Type   | Mandatory| Description                                  |
| ------ | ------ | ---- | ------------------------------------- |
| formId | string | Yes  | ID of a widget.                              |
| minute | number | Yes  | Refresh interval, in minutes. The value must be greater than or equal to 5.    |
W
wusongqing 已提交
64

Z
zengyawen 已提交
65 66
**Return value**

W
wusongqing 已提交
67 68 69
| Type         | Description                             |
| ------------- | ---------------------------------- |
| Promise\<void> |Promise used to return the result.     |
Z
zengyawen 已提交
70

W
wusongqing 已提交
71 72 73 74
**Example**

  ```js
  var formId = "12400633174999288";
75 76 77
  formProvider.setFormNextRefreshTime(formId, 5).then(() => {
      console.log('formProvider setFormNextRefreshTime success');
  }).catch((error) => {
W
wusongqing 已提交
78 79 80 81 82 83
      console.log('formProvider setFormNextRefreshTime, error:' + JSON.stringify(error));
  });
  ```

## updateForm

W
wusongqing 已提交
84
updateForm(formId: string, formBindingData: formBindingData.FormBindingData, callback: AsyncCallback&lt;void&gt;): void;
W
wusongqing 已提交
85

W
wusongqing 已提交
86
Updates a widget. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
87 88 89 90 91 92 93

**System capability**

SystemCapability.Ability.Form

**Parameters**

W
wusongqing 已提交
94 95 96 97 98
| Name| Type                                                                   | Mandatory| Description            |
| ------ | ---------------------------------------------------------------------- | ---- | ---------------- |
| formId | string                                                                 | Yes  | ID of the widget to update.|
| formBindingData | [FormBindingData](js-apis-formbindingdata.md#formbindingdata) | Yes  | Data to be used for the update.   |
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
W
wusongqing 已提交
99 100 101 102 103 104 105 106

**Example**

  ```js
  import formBindingData from '@ohos.application.formBindingData';
  var formId = "12400633174999288";
  let obj = formBindingData.createFormBindingData({temperature:"22c", time:"22:00"});
  formProvider.updateForm(formId, obj, (error, data) => {
107 108
      if (error.code) {
          console.log('formProvider updateForm, error:' + JSON.stringify(error));
W
wusongqing 已提交
109 110 111 112 113 114
      }
  });
  ```

## updateForm

W
wusongqing 已提交
115
updateForm(formId: string, formBindingData: formBindingData.FormBindingData): Promise&lt;void&gt;;
W
wusongqing 已提交
116

W
wusongqing 已提交
117
Updates a widget. This API uses a promise to return the result.
W
wusongqing 已提交
118 119 120 121 122 123 124

**System capability**

SystemCapability.Ability.Form

**Parameters**

W
wusongqing 已提交
125 126 127 128
| Name| Type                                                                   | Mandatory| Description            |
| ------ | ---------------------------------------------------------------------- | ---- | ---------------- |
| formId | string                                                                 | Yes  | ID of the widget to update.|
| formBindingData | [FormBindingData](js-apis-formbindingdata.md#formbindingdata) | Yes  | Data to be used for the update.   |
W
wusongqing 已提交
129

Z
zengyawen 已提交
130 131 132 133 134 135
**Return value**

| Type          | Description                               |
| -------------- | ----------------------------------- |
| Promise\<void> | Promise used to return the result.|

W
wusongqing 已提交
136 137 138 139 140 141
**Example**

  ```js
  import formBindingData from '@ohos.application.formBindingData';
  var formId = "12400633174999288";
  let obj = formBindingData.createFormBindingData({temperature:"22c", time:"22:00"});
142 143 144
  formProvider.updateForm(formId, obj).then(() => {
      console.log('formProvider updateForm success');
  }).catch((error) => {
W
wusongqing 已提交
145 146 147
      console.log('formProvider updateForm, error:' + JSON.stringify(error));
  });
  ```