Skip to content

Commit f330f99

Browse files
committed
v1.0.2
- Better validation errors (*finally hacked*)
1 parent 223d852 commit f330f99

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

lib/client/autoform.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ AutoForm.addInputType("fileUpload", {
22
template: "afFileUpload"
33
});
44

5-
SimpleSchema.messages({wrongFileType: "wrong file type", fileToBig: "Your filesize is too big!"})
5+
SimpleSchema.messages({
6+
uploadError: '[value]'
7+
});

lib/client/fileUpload.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

package.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Package.describe({
22
name: "ostrio:autoform-files",
33
summary: "File upload for AutoForm using ostrio:files",
44
description: "File upload for AutoForm using ostrio:files",
5-
version: "1.0.1",
5+
version: "1.0.2",
66
git: "https://github.com/VeliovGroup/meteor-autoform-file.git"
77
});
88

0 commit comments

Comments
 (0)