I have two fields itemlist and itemlistUpload
I am using react-hook-forms. I want the user to provide either one of the them. And one of them is required
How can i do the validation
import { useForm, Controller } from "react-hook-form";
import {
Col,
Row,
Form,
FormGroup,
InputGroup,
Input,
Container
} from "reactstrap";
export default function App() {
const onSubmit = (data) => {
console.log(data);
};
const { control, handleSubmit } = useForm();
return (
<Container>
<Form onSubmit={handleSubmit(onSubmit)}>
<Row className="m-3">
<Col>
<Controller
name="itemlist"
control={control}
render={({ field: { ref, ...field } }) => (
<Input
{...field}
type="textarea"
rows={10}
placeholder="itemlist"
required
innerRef={ref}
/>
)}
/>
</Col>
</Row>
<Row className="m-3">
<Col>
<FormGroup row className="mr-md-1">
<InputGroup className="mb-3">
<Controller
name="itemlist2"
control={control}
render={({ field: { ref, ...field } }) => (
<Input
{...field}
type="file"
required
innerRef={ref}
/>
)}
/>
</InputGroup>
</FormGroup>
</Col>
</Row>
</Form>
</Container>
);
}
Here is the codesandbox https://codesandbox.io/s/bitter-grass-erz7t