Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature request] input[type="file"] #989

Closed
wujekbogdan opened this issue Sep 27, 2015 · 5 comments
Closed

[Feature request] input[type="file"] #989

wujekbogdan opened this issue Sep 27, 2015 · 5 comments

Comments

@wujekbogdan
Copy link

Is there any chance to implement file input validation using FormData()? It's supported by all major browsers (and IE>=10): http://caniuse.com/#search=FormData

@marcandre
Copy link
Collaborator

Ok, IIC, you want to add a remote validation to an input of type=file, and that won't work currently because our ajax call uses something like data: {input_name: input_value}, right?

So I think it would be nice to support type=file too. Since we aim to support IE8/9 too, we should issue a warning in those cases, and continue using the basic data form unless it's a file.

Any chance you'd be able to provide a PR for this?

@wujekbogdan wujekbogdan changed the title [Feature request] input[type="file" [Feature request] input[type="file"] Sep 30, 2015
@wujekbogdan
Copy link
Author

No, not a remote validator. Regular front-end validation using FormData()

I know that FormData works only in modern browsers, and there's no reasonable polyfill for IE<10. So maybe it would be better to deliver it as a plugin (an additional validator) not as a core feature?

Here's an example of max file size valiadtor: http://jsfiddle.net/milz/pfn8fwn3/1/
This example works for Parsley 1.x

Implementing this feature in 2.x version is tricky because it's not possible to get the reference to DOM object in the callback function of window.Parsley.addValidator method.

Correct me if I'm wrong.

@marcandre
Copy link
Collaborator

I'm glad to report that it is easy to validate this in 2.2, since the arguments passed to the validators are: value, requirement, parsleyInstance. From the parsley instance, you have access to $element.

@wujekbogdan
Copy link
Author

Thank you. I was using an older version.

Thanks to this feature I was able to create a code sample for basic file[type=input] validation:
https://jsfiddle.net/02vjbLrs/14/

@marcandre
Copy link
Collaborator

I've added this to our custom validator example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants