首页 > 解决方案 > HandleSubmit 在 Redux 表单和 React Native - 没有值打印出来

问题描述

当我尝试使用 Redux Form 时,我遇到了问题,handleSubmit控制台中没有打印任何内容。

这是我的代码:

const renderTextInput = field => {
  const {
    meta: { touched, error },
    label,
    secureTextEntry,
    maxLength,
    keyboardType,
    placeholder,
    input: { onChange, ...restInput }
  } = field;
  return (
    <View>
      <InputText
        onChangeText={onChange}
        maxLength={maxLength}
        placeholder={placeholder}
        keyboardType={keyboardType}
        secureTextEntry={secureTextEntry}
        label={label}
        {...restInput}
        {...onChange}
      />
      {touched && error && <Text style={styles.errorText}>{error}</Text>}
    </View>
  );
};
class SingUp extends Component {
  onSubmit = values => {
    console.log(values);
  };
  render() {
    const { handleSubmit } = this.props;
    return (
      <View style={styles.container}>
        <View style={styles.logoContainer}>
          <Image
            style={{ height: 140, width: 140 }}
            source={require("../images/logo.png")}
          />
          <Text style={styles.logoText}>Complete el formulario</Text>
        </View>
        <View style={styles.formContainer}>
          <Field
            placeholder="Nombre y Apellido"
            value="asd"
            name="name"
            component={renderTextInput}
          />
          <Field
            placeholder="Mail"
            keyboardType="email-address"
            name="mail"
            component={renderTextInput}
          />
          <Field
            placeholder="Contraseña"
            secureTextEntry={true}
            name="password"
            component={renderTextInput}
          />
          <Field
            placeholder="Celular"
            name="tel"
            keyboardType="numeric"
            component={renderTextInput}
          />
          <Field
            placeholder="DNI"
            name="dni"
            keyboardType="numeric"
            component={renderTextInput}
          />
          <TouchableOpacity
            style={styles.button}
            onPress={handleSubmit(this.onSubmit)}
          >
            <Text style={styles.buttonText}>Crear cuenta</Text>
          </TouchableOpacity>
          <TouchableOpacity onPress={() => Actions.pop()}>
            <Text style={styles.textSingUp}> Ya tengo cuenta</Text>
          </TouchableOpacity>
        </View>
      </View>
    );
  }
}

export default reduxForm({
  form: "register",
  fields: ["name", "mail", "password", "tel", "dni"]
})(SingUp);

我从堆栈溢出中尝试了几件事,但我找不到这些的解决方案。

如果社区中的任何人可以帮助我,我将不胜感激,Ty。

标签: javascriptreactjsreact-nativeredux-form

解决方案


推荐阅读