Skip to content

Commit 8b46263

Browse files
committed
upload config 'accept' implemented to define accept values for the input
1 parent ffe0799 commit 8b46263

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

lib/client/fileUpload.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616
{{/if}}
1717
{{else}}
1818
{{#if uploadTemplate}}
19-
{{>Template.dynamic template=uploadTemplate data=currentUpload}}
19+
{{>Template.dynamic template=uploadTemplate data=uploadTemplateData}}
2020
{{else}}
2121
{{#with currentUpload}}
2222
Uploading <b>{{file.name}}</b>:
2323
<progress value="{{progress.get}}" max="100"></progress>
2424
&nbsp;
2525
<span class="progress">{{progress.get}}%</span>
2626
{{else}}
27-
<input data-files-collection-upload class="form-control af-file-upload-capture" type="file" />
27+
<input data-files-collection-upload class="form-control af-file-upload-capture" type="file" accept="{{accept}}" />
2828
{{/with}}
2929
{{/if}}
3030
{{/with}}

lib/client/fileUpload.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ Template.afFileUpload.onCreated(function () {
5151

5252
this.uploadTemplate = this.data.atts.uploadTemplate || null;
5353
this.previewTemplate = this.data.atts.previewTemplate || null;
54+
this.accept = this.data.atts.accept || null;
5455
this.insertConfig = Object.assign({}, this.data.atts.insertConfig || {});
5556
delete this.data.atts.insertConfig;
5657
this.insertConfig = Object.assign(this.insertConfig, _.pick(this.data.atts, Object.keys(defaultInsertOpts)));
@@ -80,6 +81,20 @@ Template.afFileUpload.helpers({
8081
uploadTemplate() {
8182
return Template.instance().uploadTemplate;
8283
},
84+
uploadTemplateData() {
85+
const instance = Template.instance();
86+
const currentUpload = instance.currentUpload.get();
87+
const { accept } = instance;
88+
89+
// here we can check for upload template configs, that have been added after 2.1.4 and return either
90+
// an object with "config" merged with "currentUpload" to stay backwards compatible as popssible
91+
if (accept) {
92+
const config = { config: { accept } };
93+
return Object.assign({}, config, currentUpload);
94+
} else {
95+
return currentUpload;
96+
}
97+
},
8398
currentUpload() {
8499
return Template.instance().currentUpload.get();
85100
},
@@ -93,6 +108,9 @@ Template.afFileUpload.helpers({
93108
return null;
94109
}
95110
return template.collection.findOne({_id});
111+
},
112+
accept() {
113+
return Template.instance().accept;
96114
}
97115
});
98116

0 commit comments

Comments
 (0)