@@ -4,6 +4,7 @@ Template.afFileUpload.onCreated(function () {
44 throw new Meteor . Error ( 404 , '[meteor-autoform-files] No such collection "' + this . data . atts . collection + '"' ) ;
55 }
66 this . collectionName = ( ) => this . data . atts . collection
7+ this . inputName = this . data . name ;
78 this . currentUpload = new ReactiveVar ( false ) ;
89 this . fileId = new ReactiveVar ( this . data . value ) ;
910 this . error = new ReactiveVar ( false ) ;
@@ -21,9 +22,6 @@ Template.afFileUpload.helpers({
2122 return global [ Template . instance ( ) . collectionName ( ) ] . findOne ( {
2223 _id : Template . instance ( ) . fileId . get ( )
2324 } ) ;
24- } ,
25- error ( ) {
26- return Template . instance ( ) . error . get ( ) ;
2725 }
2826} ) ;
2927
@@ -39,7 +37,7 @@ Template.afFileUpload.events({
3937 if ( e . currentTarget . files && e . currentTarget . files [ 0 ] ) {
4038 const input = $ ( e . currentTarget ) ;
4139 const parent = input . parent ( '.form-group' ) ;
42- parent . removeClass ( 'has-error' ) ;
40+ // parent.removeClass('has-error');
4341 const upload = global [ template . collectionName ( ) ] . insert ( {
4442 file : e . currentTarget . files [ 0 ] ,
4543 streams : 'dynamic' ,
@@ -52,11 +50,8 @@ Template.afFileUpload.events({
5250 } ) ;
5351
5452 upload . on ( 'error' , function ( error ) {
55- template . error . set ( error . reason ) ;
53+ AutoForm . getValidationContext ( ) . addInvalidKeys ( [ { name : Template . instance ( ) . inputName , type : "wrongFileType" , value : "" } ] )
5654 input . val ( '' ) ;
57- if ( parent [ 0 ] ) {
58- parent . addClass ( 'has-error' ) ;
59- }
6055 return ;
6156 } ) ;
6257
0 commit comments