N
N
nickname133842020-01-15 21:47:20
JavaScript
nickname13384, 2020-01-15 21:47:20

How to fix React js form validation bug?

I'm trying to validate the height and width of the uploaded image in react using Formik and Yup
link https://codesandbox.io/s/kind-architecture-4lgid
If you select an image larger than 120 x 120, there will be no error, but if you upload the image repeatedly, an error occurs
With Formik just started working
, the description of the problem is at the link

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2020-01-15
@nickname13384

.test('fileSizes', 'Resolution at least 120x120px', value => {
  return new Promise(resolve => {
    const img = new Image();
    img.onload = () => resolve(img.width >= 120 && img.height >= 120);
    img.src = window.URL.createObjectURL(value);
  });
})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question