Search code examples
jqueryvalidationformsjquery-validate

jQuery validate plugin clearing file input value in IE


I'm currently using this jQuery validate plugin and having an issue in IE where it's removing the value of file input fields whilst validating the rest of the form.

This seems to me like an onfocus issue, I select a file to upload, click on another input field and it clears the value - this only happens on the file input fields as well, any other types of input in the form keep their values fine. I've been playing around with the plugin file and nothing seems to change the fact that its clearing the field, also searched the web and can't find any help.

I've tested the issue on other browsers and the value remains in place, so it's just in IE. Is this a common issue?


Solution

  • I haven't worked with IE file INPUT elements for awhile, but I think I still remember enough to be helpful.

    As I remember it, IE clears any file INPUT that isn't set by IE itself. I think their logic is "file INPUTs should only have valid paths that the user intended, so if a file INPUT is set by JavaScript, assume that it's malicious and clear the INPUT".

    So, if your validation logic contains any kind of $("INPUT[type='file']").val(something)-like stuff, that would explain the behavior you saw. Hope that helps.