Skip to content

Commit 87ac9eb

Browse files
committed
Adding upload only option to file component.
1 parent acf7707 commit 87ac9eb

File tree

2 files changed

+24
-18
lines changed

2 files changed

+24
-18
lines changed

src/PDF.js

+19-17
Original file line numberDiff line numberDiff line change
@@ -60,23 +60,25 @@ export default class PDF extends Webform {
6060
submission.readOnly = !!this.options.readOnly;
6161
this.postMessage({ name: 'submission', data: submission });
6262
return super.setSubmission(submission).then(() => {
63-
this.formio.getDownloadUrl().then((url) => {
64-
// Add a download button if it has a download url.
65-
if (!url) {
66-
return;
67-
}
68-
if (!this.downloadButton) {
69-
this.downloadButton = this.ce('a', {
70-
href: url,
71-
target: '_blank',
72-
style: 'position:absolute;right:10px;top:110px;cursor:pointer;'
73-
}, this.ce('img', {
74-
src: require('./pdf.image'),
75-
style: 'width:3em;'
76-
}));
77-
this.element.insertBefore(this.downloadButton, this.iframe);
78-
}
79-
});
63+
if (this.formio) {
64+
this.formio.getDownloadUrl().then((url) => {
65+
// Add a download button if it has a download url.
66+
if (!url) {
67+
return;
68+
}
69+
if (!this.downloadButton) {
70+
this.downloadButton = this.ce('a', {
71+
href: url,
72+
target: '_blank',
73+
style: 'position:absolute;right:10px;top:110px;cursor:pointer;'
74+
}, this.ce('img', {
75+
src: require('./pdf.image'),
76+
style: 'width:3em;'
77+
}));
78+
this.element.insertBefore(this.downloadButton, this.iframe);
79+
}
80+
});
81+
}
8082
});
8183
}
8284

src/components/file/File.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ export default class FileComponent extends BaseComponent {
1313
imageSize: '200',
1414
filePattern: '*',
1515
fileMinSize: '0KB',
16-
fileMaxSize: '1GB'
16+
fileMaxSize: '1GB',
17+
uploadOnly: false
1718
}, ...extend);
1819
}
1920

@@ -184,6 +185,9 @@ export default class FileComponent extends BaseComponent {
184185
}
185186

186187
createFileLink(file) {
188+
if (this.options.uploadOnly) {
189+
return file.originalName || file.name;
190+
}
187191
return this.ce('a', {
188192
href: file.url, target: '_blank',
189193
onClick: this.getFile.bind(this, file)

0 commit comments

Comments
 (0)