-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfileformexample.jsx
More file actions
56 lines (51 loc) · 1.4 KB
/
Copy pathfileformexample.jsx
File metadata and controls
56 lines (51 loc) · 1.4 KB
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
import { Form, Button, CustomInput } from "@panely/components"
import { useForm, Controller } from "react-hook-form"
import { yupResolver } from "@hookform/resolvers"
import * as yup from "yup"
function FileFormExample() {
// Define Yup schema for form validation
const schema = yup.object().shape({
file: yup
.mixed()
.required("You need to provide file")
})
const { control, handleSubmit, errors } = useForm({
// Apply Yup as resolver for react-hook-form
resolver: yupResolver(schema),
// Define the default values for all input forms
defaultValues: {
file: undefined
}
})
// Handle form submit event
const onSubmit = data => {
// Display array of file data
console.log(data.file)
}
return (
<Form onSubmit={handleSubmit(onSubmit)}>
{/* BEGIN Form Group */}
<Form.Group>
<Controller
control={control}
name="file"
render={({ onChange, name, ref }) => (
<CustomInput
type="file"
id="file"
label="Input you file"
invalid={Boolean(errors.file)}
onChange={e => onChange(e.target.files)}
innerRef={ref}
/>
)}
/>
</Form.Group>
{/* END Form Group */}
<Button type="submit" variant="primary">
Submit
</Button>
</Form>
)
}
export default FileFormExample