Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

enter image description here 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>
    );
like image 918
askemeline Avatar asked Dec 13 '25 15:12

askemeline


1 Answers

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.

like image 69
Caio Ragazzi Avatar answered Dec 15 '25 09:12

Caio Ragazzi