getFieldDecorator, but the binding onChange method is valid
code is as follows:
const { Form, Icon, Input, Button, Checkbox, } = antd;
const FormItem = Form.Item;
class NormalLoginForm extends React.Component {
handleSubmit = (e) => {
e.preventDefault();
this.props.form.validateFields((err, values) => {
if (!err) {
console.log("Received values of form: ", values);
}
});
}
getInfo = (e) => {
const {checked} = e.target;
console.log("", checked);
setTimeout(() => {
const values = this.props.form.getFieldsValue();
console.log("", e, values);
}, 0)
}
render() {
const { getFieldDecorator } = this.props.form;
return (
<Form onSubmit={this.handleSubmit} className="login-form">
<FormItem>
{getFieldDecorator("userName", {
rules: [{ required: true, message: "Please input your username!" }],
/*onChange: (e) =>{
if(e.target.value == ""){
this.props.form.setFieldsValue({
remember:false
});
}
console.log("kjjjjkkkkkk");
}*/
onBlur: (e) =>{
if(e.target.value == ""){
this.props.form.setFieldsValue({
remember:false
});
}
console.log("kjjjjkkkkkk");
}
})(
<Input prefix={<Icon type="user" style={{ color: "rgba(0,0,0,.25)" }} />} placeholder="Username" />
)}
</FormItem>
<FormItem>
{getFieldDecorator("password", {
rules: [{ required: true, message: "Please input your Password!" }],
})(
<Input prefix={<Icon type="lock" style={{ color: "rgba(0,0,0,.25)" }} />} type="password" placeholder="Password" />
)}
</FormItem>
<FormItem>
{getFieldDecorator("remember", {
valuePropName: "checked",
initialValue: false,
})(
<Checkbox onChange={this.getInfo}>Remember me</Checkbox>
)}
<a className="login-form-forgot" href="">Forgot password</a>
<Button type="primary" htmlType="submit" className="login-form-button">
Log in
</Button>
Or <a href="">register now!</a>
</FormItem>
</Form>
);
}
}
const WrappedNormalLoginForm = Form.create()(NormalLoginForm);
ReactDOM.render(<WrappedNormalLoginForm />, mountNode);
the console will not be able to output "kjjjjkkkkkk" after changing onChange to onBlur. Is there a problem with where I wrote it? Or is it that onBlur bindings can only be bound to form elements, not anonymously as above? But I think there can be other events in the official website getFieldDecorator, just that onChange is the default event.