bhrott / react-native-masked-text

A pure javascript masked text and input text component for React-Native.
MIT License
1.6k stars 251 forks source link

TextInputMask + Formik + Yup #221

Open danielrmartins opened 4 years ago

danielrmartins commented 4 years ago

Is it possible to use TextInputMask with Formik and Yup?

alecpo commented 4 years ago

Yes, I'm using right now. :)

IkaroAlef commented 3 years ago

Yes, I'm using right now. :)

can you provide an example? I'm using this but i'm having a little bug on handling errors with formik's "errors." and "touched.";

cloudworkpro-hassen commented 3 years ago

I am also having trouble with Errors and Touched from formik is it possible to provide an example on how you handled this?

danielrmartins commented 3 years ago

Create an Input with TextInput Mask:

const FormInputCPF = ({ value, placeholder, ...rest }) => (
  <TextInputMask
    maxLength={255}
    ref={ref => (cpfField = ref)}
    {...rest}
    value={value}
    type={'cpf'}
    placeholder={placeholder}
    placeholderTextColor="gray"
    keyboardType={'numeric'}
    style={styles.item}
    onSubmitEditing={() => phone.focus()}
  />
);

then, inside the Formik:

<Item>
      <FormInputCPF
        value={values.cpf}
        placeholder={'CPF'}
        onChangeText={handleChange('cpf')}
        onBlur={handleBlur('cpf')}
        changeText={values.cpf}
      />
 </Item>
  <Text style={styles.textError}>
      {touched.cpf && errors.cpf}
  </Text>