react-native-masked-text icon indicating copy to clipboard operation
react-native-masked-text copied to clipboard

TextInputMask + Formik + Yup

Open danielrmartins opened this issue 4 years ago • 4 comments

Is it possible to use TextInputMask with Formik and Yup?

danielrmartins avatar Mar 24 '20 20:03 danielrmartins

Yes, I'm using right now. :)

alecpo avatar Mar 26 '20 13:03 alecpo

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.";

IkaroAlef avatar Dec 19 '20 04:12 IkaroAlef

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

cloudworkpro-hassen avatar Apr 12 '21 02:04 cloudworkpro-hassen

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>

danielrmartins avatar Apr 22 '21 14:04 danielrmartins