UNPKG

3.15 kBTypeScriptView Raw
1import { ComponentType } from 'react'
2import { StandardProps, CommonEventFunction } from './common'
3
4interface FormProps extends StandardProps {
5 /** 是否返回 `formId` 用于发送模板消息。
6 * @default false
7 * @supported weapp, h5
8 */
9 reportSubmit?: boolean
10
11 /** 等待一段时间(毫秒数)以确认 `formId` 是否生效。
12 * 如果未指定这个参数,`formId` 有很小的概率是无效的(如遇到网络失败的情况)。
13 * 指定这个参数将可以检测 `formId` 是否有效,
14 * 以这个参数的时间作为这项检测的超时时间。
15 * 如果失败,将返回 `requestFormId:fail` 开头的 `formId`。
16 * @default 0
17 * @supported weapp
18 */
19 reportSubmitTimeout?: number
20
21 /** 携带 form 中的数据触发 submit 事件
22 * event.detail = { value : {'name': 'value'} , formId: '' }
23 * @supported weapp, rn, tt
24 */
25 onSubmit?: CommonEventFunction<FormProps.onSubmitEventDetail>
26
27 /** 表单重置时会触发 reset 事件
28 * @supported weapp, h5, rn, tt
29 */
30 onReset?: CommonEventFunction
31}
32
33declare namespace FormProps {
34 interface onSubmitEventDetail {
35 /** 当点击 `<form>` 表单中 `form-type` 为 `submit` 的 `<button>` 组件时,
36 * 会将表单组件中的 `value` 值进行提交,
37 * 需要在表单组件中加上 `name` 来作为 `key`。
38 */
39 value?: {
40 [formItemName: string]: any
41 }
42 /** 当 `reportSubmit` 为 `true` 时,返回 `formId` 用于发送模板消息。
43 */
44 formId?: string
45 }
46}
47
48/** 表单。将组件内的用户输入的 switch input checkbox slider radio picker 提交。
49 *
50 * 当点击 form 表单中 form-type 为 submit 的 button 组件时,会将表单组件中的 value 值进行提交,需要在表单组件中加上 name 来作为 key。
51 * @classification forms
52 * @supported weapp, h5, rn
53 * @example_react
54 * ```tsx
55 * class App extends Component {
56 *
57 * formSubmit = e => {
58 * console.log(e)
59 * }
60 *
61 * formReset = e => {
62 * console.log(e)
63 * }
64 *
65 * render () {
66 * return (
67 * <Form onSubmit={this.formSubmit} onReset={this.formReset} >
68 * <View className='example-body'>
69 * <Switch name='switch' className='form-switch'></Switch>
70 * </View>
71 * </Form>
72 * )
73 * }
74 * }
75 * ```
76 * @example_vue
77 * ```html
78 * <template>
79 * <form `@submit="formSubmit" `@reset="formReset" >
80 * <view class="taro-example-body">
81 * <switch name="switch" class="form-switch"></Switch>
82 * </view>
83 * <view class="taro-example-btns">
84 * <button form-type="submit">Submit</button>
85 * <button type="default" form-type="reset">Reset</button>
86 * </view>
87 * </form>
88 * </template>
89 *
90 * <script>
91 * export default {
92 * data() {
93 * return {}
94 * },
95 * methods: {
96 * formSubmit (e) {
97 * console.log(e)
98 * },
99 *
100 * formReset (e) {
101 * console.log(e)
102 * }
103 * }
104 * }
105 * </script>
106 * ```
107 * @see https://developers.weixin.qq.com/miniprogram/dev/component/form.html
108 */
109declare const Form: ComponentType<FormProps>
110
111export { Form, FormProps }