UNPKG

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