@@ -3,11 +3,12 @@ Template.afFileUpload.onCreated(function () {
33 if ( ! this . collection ) {
44 throw new Meteor . Error ( 404 , '[meteor-autoform-files] No such collection "' + this . data . atts . collection + '"' ) ;
55 }
6+
67 this . collectionName = ( ) => this . data . atts . collection
7- this . inputName = this . data . name ;
8+
89 this . currentUpload = new ReactiveVar ( false ) ;
10+ this . inputName = this . data . name ;
911 this . fileId = new ReactiveVar ( this . data . value ) ;
10- this . error = new ReactiveVar ( false ) ;
1112 return ;
1213} ) ;
1314
@@ -35,23 +36,22 @@ Template.afFileUpload.events({
3536 } ,
3637 'change [data-files-collection-upload]' ( e , template ) {
3738 if ( e . currentTarget . files && e . currentTarget . files [ 0 ] ) {
38- const input = $ ( e . currentTarget ) ;
39- const parent = input . parent ( '.form-group' ) ;
40- //parent.removeClass('has-error');
4139 const upload = global [ template . collectionName ( ) ] . insert ( {
4240 file : e . currentTarget . files [ 0 ] ,
4341 streams : 'dynamic' ,
4442 chunkSize : 'dynamic'
4543 } , false ) ;
4644
4745 upload . on ( 'start' , function ( ) {
46+ AutoForm . getValidationContext ( ) . resetValidation ( ) ;
4847 template . currentUpload . set ( this ) ;
4948 return ;
5049 } ) ;
5150
5251 upload . on ( 'error' , function ( error ) {
53- AutoForm . getValidationContext ( ) . addInvalidKeys ( [ { name : Template . instance ( ) . inputName , type : "wrongFileType" , value : "" } ] )
54- input . val ( '' ) ;
52+ AutoForm . getValidationContext ( ) . resetValidation ( ) ;
53+ AutoForm . getValidationContext ( ) . addInvalidKeys ( [ { name : Template . instance ( ) . inputName , type : "uploadError" , value : error . reason } ] ) ;
54+ $ ( e . currentTarget ) . val ( '' ) ;
5555 return ;
5656 } ) ;
5757
0 commit comments