Skip to content

Commit

Permalink
netteForms.js: support checking file name via pattern rule using HTML…
Browse files Browse the repository at this point in the history
…5 File API

* this is a complement to nette#175 so validating file names via pattern works on both client and server
  • Loading branch information
renekliment committed Jul 25, 2018
1 parent 177fbe3 commit 6ecdb13
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/assets/netteForms.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,8 +449,24 @@
},

pattern: function(elem, arg, val) {
if (typeof arg !== 'string') {
return null;
}

try {
return typeof arg === 'string' ? (new RegExp('^(?:' + arg + ')$')).test(val) : null;
var regExp = new RegExp('^(?:' + arg + ')$');

if (window.FileList && val instanceof FileList) {
for (var i = 0; i < val.length; i++) {
if (!regExp.test(val[i].name)) {
return false;
}
}

return true;
}

return regExp.test(val);
} catch (e) {} // eslint-disable-line no-empty
},

Expand Down

0 comments on commit 6ecdb13

Please sign in to comment.