medipass / react-payment-inputs

A React Hook & Container to help with payment card input fields.
https://medipass.github.io/react-payment-inputs
342 stars 62 forks source link

Expiry date don't format input data #41

Open carloscba opened 4 years ago

carloscba commented 4 years ago

I'm working with react-payment-inputs and material ui:

const { meta, getCardNumberProps, getExpiryDateProps, getCVCProps, getCardImageProps } = usePaymentInputs();
const { erroredInputs, touchedInputs } = meta;

...

const [expiryDate, setExpiryDate] = useState();
const handleChangeExpiryDate = (event) => setExpiryDate(event.target.value);

...

<TextField
  inputProps={{ "data-testid": "expireDate" }}
  {...getExpiryDateProps({ onChange: handleChangeExpiryDate })}
  defaultValue = { expiryDate }
  error={ (erroredInputs.expiryDate && touchedInputs.expiryDate) ? true : false } 
  helperText= { (touchedInputs.expiryDate) && erroredInputs.expiryDate }
  label="Expiry Date"
  type="text"
  margin="dense"
  fullWidth
/>                                

In this example validation work fine but don't format the input date as 00/00

Screenshot Capture - 2020-07-02 - 12-49-12

If I implement a simple input everything it's ok

<input {...getExpiryDateProps({ onChange: handleChangeExpiryDate })} value={expiryDate} />

Saludos, muchas gracias.

kguptaaa commented 3 years ago

Hi, You need to pass the getter method to inputProps like this:

<TextField
  inputProps={getExpiryDateProps({ onChange: handleChangeExpiryDate })}
  defaultValue = { expiryDate }
  error={ (erroredInputs.expiryDate && touchedInputs.expiryDate) } 
  helperText= { (touchedInputs.expiryDate) && erroredInputs.expiryDate }
  label="Expiry Date"
  type="text"
  margin="dense"
  fullWidth
/>