How to validate FormData using Modernizr and YesNope Javascript

How to validate a FormData object using Modernizr and YepNope ?

<script>
yepnope({  
  test : what.to.check,  
  yep  : 'normal.js',  
  nope : 'flashupload.js'  
});      
</script>
+5
source share
2 answers

I was looking for a way to upgrade the Modernizer FormDatathe other day and could not find it.

However, this is easy to do without the Upgrade:

window.FormData // exists if it exists, undefined if it doesn't!

So:

yepnope({  
  test : "FormData" in window,
  yep  : 'normal.js',  
  nope : 'flashupload.js'  
});   

FWIW, compatibility with MDC forFormData says you will target:

  • Chrome 7+
  • Firefox 4.0
  • IE 10+
  • Safari 5+

... Opera support unknown

+9
source

You can extend Modernizr with custom tests. Just drop this at the end of your Modernizr file:

Modernizr.addTest('formdata', ('FormData' in window));
+4
source

All Articles