diff --git a/i18n/en.json b/i18n/en.json index 56b08fb..9d02eef 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -41,6 +41,7 @@ "fieldRequired": "Is this field required?", "file": "File attachment", "fileAllowMultiple": "Allow multiple file attachments", + "fileLimitSize": "Limit file size?", "fileMaxSize": "Max file attachment size", "fileMaxSizeError": "File is too large '%1$s' (max size: %2$s).", "fileMaxSizeHelp": "In Bytes", diff --git a/modules/@apostrophecms/form-file-field-widget/index.js b/modules/@apostrophecms/form-file-field-widget/index.js index a1ed3f9..a41a27d 100644 --- a/modules/@apostrophecms/form-file-field-widget/index.js +++ b/modules/@apostrophecms/form-file-field-widget/index.js @@ -10,10 +10,18 @@ module.exports = { type: 'boolean', def: true }, + limitSize: { + label: 'aposForm:fileLimitSize', + type: 'boolean', + def: false + }, maxSize: { label: 'aposForm:fileMaxSize', help: 'aposForm:fileMaxSizeHelp', - type: 'integer' + type: 'integer', + if: { + limitSize: true + } } } }, diff --git a/modules/@apostrophecms/form-file-field-widget/views/widget.html b/modules/@apostrophecms/form-file-field-widget/views/widget.html index 0a5365f..18936e7 100644 --- a/modules/@apostrophecms/form-file-field-widget/views/widget.html +++ b/modules/@apostrophecms/form-file-field-widget/views/widget.html @@ -16,7 +16,7 @@ class="apos-form-input {{ prependIfPrefix('__input') }}" type="file" id="{{ id }}" {% if widget.allowMultiple %}multiple{% endif %} - {% if widget.maxSize %} + {% if widget.limitSize and widget.maxSize %} data-max-size="{{ widget.maxSize }}" data-max-size-error="{{ __t('aposForm:fileMaxSizeError') }}" data-file-size-units="{{ widget.fileSizeUnits | jsonAttribute }}"