问题
form render:
return (
<form onSubmit={handleSubmit}>
<Field
name="login"
component={RenderTextField}
label="Login"
/>
<Field
name="password"
component={RenderTextField}
label="Password"
/>
</form>
)
validate:
const RenderTextField = ({
label,
input,
meta: { touched, invalid, error },
...custom
},props) => {
const classes = useStyles();
return (
<TextField
label={label}
placeholder={label}
error={touched && invalid}
helperText={touched && error}
{...input}
{...custom}
/>
);
}
const validate = values => {
console.log(values);
const errors = {}
const requiredFields = [
'login',
'password',
]
requiredFields.forEach(field => {
if (!values[field]) {
errors[field] = 'Required'
}
})
if (
values.email &&
!/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i.test(values.email)
) {
errors.email = 'Invalid email address'
}
return errors
}
I don't know where the error is, it's only entered in my validate once and I can't type anything in my textfield I exported my form correctly, the validation I got from the redux form documentation my RenderTextField too can anybody help me?
//
My validation happens normal even without me clicking on the text fields it validates first and returns me:
the errors:
{login: "Required", password: "Required"}
but I can't write in my textfield,
I found out that the problem is:
{...input}
{...custom}
来源:https://stackoverflow.com/questions/59288405/react-textfield-redux-form-component-does-not-allow-writing