-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCustomFormField.tsx
61 lines (56 loc) · 2.05 KB
/
CustomFormField.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
54
55
56
57
58
59
60
61
import React, { FC } from 'react'
import { Field, Form, Formik, FormikProps } from 'formik';
import { Form as TeaForm, FormItemProps } from "tea-component/lib/form";
import { Input, InputProps } from "tea-component/lib/input";
import { Select } from 'tea-component/lib/select';
type CustomInputProps = Partial<InputProps> & Pick<FormItemProps, "label" | "name"> & {
}
type CustomSelectProps = Partial<InputProps> & Pick<FormItemProps, "label" | "name"> & {
options: string[]
}
export const CustomInput:FC<CustomInputProps> = props => {
// console.log('---CustomInput',props,props.name)
return (
<Field name={props.name}>
{
({
field, // { name, value, onChange, onBlur }
form: { touched, errors }, // also values, setXXXX, handleXXXX, dirty, isValid, status, etc.
meta,
}) => {
return (
<TeaForm.Item label={props.label} required={props.required} status={meta.touched && meta.error ? 'error': undefined } message={meta.error}>
<Input type="text" {...field} onChange={(value,ctx)=> {
// console.log('-=--',value,e)
field.onChange(ctx.event)
}} />
</TeaForm.Item>
)
}
}
</Field>
)
}
export const CustomSelect:FC<CustomSelectProps> = props => {
// console.log('---CustomInput',props,props.name)
return (
<Field name={props.name}>
{
({
field, // { name, value, onChange, onBlur }
form: { touched, errors }, // also values, setXXXX, handleXXXX, dirty, isValid, status, etc.
meta,
}) => {
return (
<TeaForm.Item label={props.label} required={props.required} status={meta.touched && meta.error ? 'error': undefined } message={meta.error}>
<Select {...field} options={props.options.map(value=>({value}))} onChange={(value,ctx)=> {
// console.log('-=--',value,e)
field.onChange(ctx.event)
}} />
</TeaForm.Item>
)
}
}
</Field>
)
}