js-components-container-form.md 2.0 KB
Newer Older
E
ester.zhou 已提交
1
# form
Z
zengyawen 已提交
2

E
ester.zhou 已提交
3 4 5
>  **NOTE**
>
>  This component is supported since API version 6. Updates will be marked with a superscript to indicate their earliest API version.
Z
zengyawen 已提交
6

E
ester.zhou 已提交
7 8 9 10
The **\<form>** component allows the content in **input** elements to be submitted and reset.


## Required Permissions
Z
zengyawen 已提交
11 12 13

None

E
ester.zhou 已提交
14 15

## Child Components
Z
zengyawen 已提交
16 17 18 19

Supported


E
ester.zhou 已提交
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
## Attributes

The [universal attributes](../arkui-js/js-components-common-attributes.md) are supported.


## Styles

The [universal styles](../arkui-js/js-components-common-styles.md) are supported.


## Events

In addition to the [universal events](../arkui-js/js-components-common-events.md), the following events are supported.

| Name| Parameter| Description|
| -------- | -------- | -------- |
| submit | FormResult | Triggered when the **Submit** button is touched.|
| reset | - | Triggered when the **Reset** button is clicked.|

**Table 1** FormResult

| Name| Type| Description|
| -------- | -------- | -------- |
| value | Object | Values of **name** and **value** of the input element.|


## Methods

The [universal methods](../arkui-js/js-components-common-methods.md) are supported.


## Example

```html
Z
zengyawen 已提交
54 55
<!-- xxx.hml -->
<form onsubmit='onSubmit' onreset='onReset'>
Z
zengyawen 已提交
56
  <div style="width: 600px;height: 150px;flex-direction: row;justify-content: space-around;">
Z
zengyawen 已提交
57
    <label>Option 1</label>
Z
zengyawen 已提交
58
    <input type='radio' name='radioGroup' value='radio1'></input>
Z
zengyawen 已提交
59
    <label>Option 2</label>
Z
zengyawen 已提交
60 61 62
    <input type='radio' name='radioGroup' value='radio2'></input>
  </div>
  <text style="margin-left: 50px;margin-bottom: 50px;">Enter text</text>
Z
zengyawen 已提交
63
  <input type='text' name='user'></input>
Z
zengyawen 已提交
64 65 66 67
  <div style="width: 600px;height: 150px;margin-top: 50px;flex-direction: row;justify-content: space-around;">
    <input type='submit'>Submit</input>
    <input type='reset'>Reset</input>
  </div>
Z
zengyawen 已提交
68 69 70
</form>
```

E
ester.zhou 已提交
71
```js
Z
zengyawen 已提交
72 73 74 75 76 77 78 79 80 81 82 83
// xxx.js
export default{
  onSubmit(result) {
    console.log(result.value.radioGroup) // radio1 or radio2
    console.log(result.value.user) // text input value
  },
  onReset() {
    console.log('reset all value')
  }
}
```

E
ester.zhou 已提交
84
![001](figures/001.gif)