Skip to content

Commit 37d6804

Browse files
committed
validation error messages
1 parent af5b38d commit 37d6804

File tree

3 files changed

+6
-12
lines changed

3 files changed

+6
-12
lines changed

lib/client/autoform.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
AutoForm.addInputType("fileUpload", {
22
template: "afFileUpload"
3-
});
3+
});
4+
5+
SimpleSchema.messages({wrongFileType: "wrong file type", fileToBig: "Your filesize is too big!"})

lib/client/fileUpload.html

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
<span class="progress">{{progress}}%</span>
1616
{{else}}
1717
<input data-files-collection-upload class="form-control af-file-upload-capture" type="file" />
18-
{{#if error}}
19-
<span class="help-block">{{error}}</span>
20-
{{/if}}
2118
{{/with}}
2219
{{/with}}
2320
</template>

lib/client/fileUpload.js

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

Comments
 (0)