Skip to content

Commit ecca771

Browse files
reneklimentdg
authored andcommitted
netteForms.js: support checking file name via pattern rule using HTML5 File API (#186)
* this is a complement to #175 so validating file names via pattern works on both client and server
1 parent 177fbe3 commit ecca771

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/assets/netteForms.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,24 @@
449449
},
450450

451451
pattern: function(elem, arg, val) {
452+
if (typeof arg !== 'string') {
453+
return null;
454+
}
455+
452456
try {
453-
return typeof arg === 'string' ? (new RegExp('^(?:' + arg + ')$')).test(val) : null;
457+
var regExp = new RegExp('^(?:' + arg + ')$');
458+
459+
if (window.FileList && val instanceof FileList) {
460+
for (var i = 0; i < val.length; i++) {
461+
if (!regExp.test(val[i].name)) {
462+
return false;
463+
}
464+
}
465+
466+
return true;
467+
}
468+
469+
return regExp.test(val);
454470
} catch (e) {} // eslint-disable-line no-empty
455471
},
456472

0 commit comments

Comments
 (0)