简体   繁体   中英

How to remove space autofill in react native

I have a TextInput and when I autofill my email address I have a space after my email.

在此处输入图片说明 I try this

 const email = values.email.trim();

and also

 const email = values.email.replace(/\s+/g, ' ');

but it's doesn't work. Someone know how to remove the space after the autofill?


    return (
      <Formik
        enableReinitialize={true}
        initialValues={{ email: this.props.navigation.getParam("email") }}
        validationSchema={yup.object().shape({
          email: yup
            .string()
        })}
        onSubmit={async (values) => {
          const email = values.email;
        }
      }
      >
        {({ handleChange, handleSubmit, values, errors, touched, setFieldTouched }) => (
          <View>
          {
            <View>
              <TextInput
                value={values.email}
                placeholder="Email"
                autoCapitalize="none"
                autoCorrect={false}
                onBlur={() => setFieldTouched("email")}
                onChangeText={handleChange("email")}
                autoCompleteType={"email"}
              />
              <View>
                <TouchableOpacity
                  onPress={handleSubmit}
                >
                  <Text style={styles.textButton}>Valider</Text>
                </TouchableOpacity>
              </View>
            </View>
        )}
      </Formik>
    );

If you haven't found a solution for this situation yet, here's one way that solves it:

onChangeText={(val) => setFieldValue('login', val.trim())}

Instead of using handleChanges , you can use setFieldValue , then "trim" val .

<Text
...
value={this.state.emailID}
/>

Reuse your trim logic and assign the new value to the state variable(emailID) in "onChangeText" of the textinput

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM