}
}
}
+
+ // Check the current file size (in KB)
+ const file_size = field_data.files[0].size / 1024;
+ const max_size = BUGZILLA.param.maxattachmentsize;
+ const invalid = file_size > max_size;
+ const message = invalid ? `This file (<strong>${(file_size / 1024).toFixed(1)} MB</strong>) is larger than the ` +
+ `maximum allowed size (<strong>${(max_size / 1024).toFixed(1)} MB</strong>).<br>Please consider uploading it ` +
+ `to an online file storage and sharing the link in a bug comment instead.` : '';
+ const message_short = invalid ? 'File too large' : '';
+ const $error = document.querySelector('#data-error');
+
+ // Show an error message if the file is too large
+ $error.innerHTML = message;
+ field_data.setCustomValidity(message_short);
+ field_data.setAttribute('aria-invalid', invalid);
}
function clearAttachmentFields() {
<em>Enter the path to the file on your computer</em> (or
<a id="attachment_data_controller">
paste text as attachment</a>).<br>
- <input type="file" id="data" name="data" size="50">
+ <input type="file" id="data" name="data" size="50" aria-errormessage="data-error" aria-invalid="false">
+ <div id="data-error" class="warning" aria-live="assertive"><div>
</td>
</tr>
<tr class="attachment_text_field">
[%# Reset this whenever the page loads so that the JS state is up to date %]
<script [% script_nonce FILTER none %]>
$(function() {
- $("#file").on("change", function() {
+ $("#data").on("change", function() {
DataFieldHandler();
// Fire event to keep take-bug in sync.
$("#ispatch").change();
[%- js_BUGZILLA = {
param => {
+ maxattachmentsize => Param('maxattachmentsize'),
maxusermatches => Param('maxusermatches'),
splinter_base => Param('splinter_base'),
},