React Textfield / redux form component does not allow writing

孤者浪人 提交于 2020-01-05 05:21:53

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!