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

3
> **NOTE**<br>
W
wusongqing 已提交
4 5
> 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 已提交
6
Provides APIs related to the widget provider.
W
wusongqing 已提交
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

## Modules to Import

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

## Required Permissions

None.

## setFormNextRefreshTime

setFormNextRefreshTime(formId: string, minute: number, callback: AsyncCallback&lt;void&gt;): void;

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

**System capability**

SystemCapability.Ability.Form

**Parameters**

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

**Example**

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

## setFormNextRefreshTime

setFormNextRefreshTime(formId: string, minute: number): Promise&lt;void&gt;;

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

**System capability**

SystemCapability.Ability.Form

**Parameters**

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

Z
zengyawen 已提交
64 65 66 67 68 69
**Return value**

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

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

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

## updateForm

updateForm(formId: string, formBindingData: FormBindingData, callback: AsyncCallback&lt;void&gt;): void;

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

**System capability**

SystemCapability.Ability.Form

**Parameters**

  | Name| Type                                                                   | Mandatory| Description            |
  | ------ | ---------------------------------------------------------------------- | ---- | ---------------- |
W
wusongqing 已提交
95
  | formId | string                                                                 | Yes  | ID of the widget to update.|
W
wusongqing 已提交
96 97 98 99 100 101 102 103 104 105
  | 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.|

**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) => {
106 107
      if (error.code) {
          console.log('formProvider updateForm, error:' + JSON.stringify(error));
W
wusongqing 已提交
108 109 110 111 112 113 114 115
      }
  });
  ```

## updateForm

updateForm(formId: string, formBindingData: FormBindingData): Promise&lt;void&gt;;

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

**System capability**

SystemCapability.Ability.Form

**Parameters**

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

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

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

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

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