NewOldMax / react-form-validator-core

Core validator component for react forms
MIT License
95 stars 44 forks source link

File input validators not working as expected #55

Closed IvanTC95 closed 5 years ago

IvanTC95 commented 5 years ago

I have added these props to my file input:

validators={['isFile', 'maxFileSize:' + 2 * 1024 * 1024, 'allowedExtensions:image/png,image/jpeg']}
errorMessages={['File not valid.', 'The file size must not exceed 2MB.', 'The file must be png or jpeg.']}

But when I don't add a file, it still shows "File not valid" (or the first error of the array)

IvanTC95 commented 5 years ago

Is this a bug or...? @NewOldMax

NewOldMax commented 5 years ago

Hi, can you reproduce your issue at https://codesandbox.io/s/new ?

DeepakM02 commented 5 years ago

hey @NewOldMax Please check it and tell me if i did any thing wrong here link

sirajalam049 commented 5 years ago

@DeepakM02 , I saw your codes in the given link, I couldn't identify any problem. Can you please explain what the problem is that you are having?

DeepakM02 commented 5 years ago

Validation are not working when you submit after uploading any file that does not match to rules.

NewOldMax commented 5 years ago

@DeepakM02 check this one https://codesandbox.io/embed/bold-bush-865xl please use latest version of package if you can

DeepakM02 commented 5 years ago

This is working but my shared link is not working. What's wrong with that. did i do something wrong ? I did as they instructed in documentation.

NewOldMax commented 5 years ago

@IvanTC95 validation is triggering after every input change. So if you don't select any file it will trigger change with undefined value so isFile checks this value

NewOldMax commented 5 years ago

@DeepakM02 you can't set file value to <input type="file"> directly so your example won't work. You can follow my code as well to build custom validations

DeepakM02 commented 5 years ago

Please Update your documentation on github and npm portal because there you gave example with

NewOldMax commented 5 years ago

@DeepakM02 now you can see FileValidator example in readme