item at form to show up form fields here is my code
import { Form, Input, Button, Select, } from 'antd';
import axios from "axios";
render() {
const isLoading = this.state.isLoading;
return (
<>
<Form className={'auth-form'} onSubmit={(e) => { this.onSubmit(e) }}>
<h3 className={'mb-5 text-center'}>Candidate Sign Up</h3>
<Form.Item
label=""
name="email"
rules={[{ required: true, type: 'email', message: 'Please enter email address'}]}
>
<Input className={'ks-form-control'} placeholder={'Enter Email'} onChange={this.onChangehandler} />
</Form.Item>
<Form.Item
label=""
name="password"
rules={[{ required: true, message: 'Please input your password!' }]}
>
<Input.Password className={'ks-form-control'} placeholder={'Password'} />
</Form.Item>
<Form.Item
label=""
name="confirmPassword"
rules={[{ required: true, message: 'Please confirm your password!' }]}
>
<Input.Password className={'ks-form-control'} placeholder={'Confirm Password'} />
</Form.Item>
<Form.Item >
<Button className={'btn-custom px-4 py-2 d-block w-100'} type="primary" htmlType="submit">
Create an account
</Button>
</Form.Item>
</Form>
</>
)
}
Here is the code for submithandler. I want to show message comming from api and custom message with below code at rules={[{}]}
msg: response.data.message
On submit handler
onSubmitHandler = (e) => {
e.preventDefault();
this.setState({ isLoading: true });
axios
.post("http://127.0.0.1:8000/api/user-signup", this.state.signupData)
.then((response) => {
this.setState({ isLoading: false });
if (response.data.status === 200) {
this.setState({
msg: response.data.message // message comming from api
});
}
if (response.data.status === "failed") {
this.setState({ msg: response.data.message }); // message comming from api
}
});
}
The valiations for all fields working fine with rules={[]} . But I want show error based on api response like if a email already registered then this will show message 'email already exists' Please let me know how can i do this