Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SAK-40229 Content screen reader announcing file upload to dropbox #12995

Merged
merged 7 commits into from
Nov 26, 2024
Merged
1 change: 1 addition & 0 deletions content/content-bundles/resources/types.properties
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ processmessage.save.html=Saving HTML page
processmessage.save.text=Saving text document
processmessage.save.file=Saving new file(s)
processmessage.save.url=Saving link(s)
label.success = Successfully uploaded: {0}
label.time = Time:
label.update = Update
label.upl = Upload New Version Now
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
<label for="MultipleFolderContent">$tlang.getString("label.upload")</label>
#end
<input type="file" name="MultipleFolderContent" id="MultipleFolderContent" class="upload" onChange="handleFileChange()"/>
<div id="fileUploadFeedback" aria-live="polite" class="upload-feedback d-none" role="status">
$tlang.getString('label.success')
</div>
</div>
<div class="form-group">
<label for="MultipleFolderDisplayName">$tlang.getString("label.display")</label>
Expand Down Expand Up @@ -186,47 +189,61 @@
{
const fileField = document.getElementById('MultipleFolderContent');
const nameField = document.getElementById('MultipleFolderDisplayName');
const feedback = document.getElementById('fileUploadFeedback');

## Goal: update the display name field. But if the user provided their own display name, don't overwrite it
if (fileField.files.length > 0)
{
feedback.textContent = `$tlang.getString('label.success')`.replace("{0}", fileField.files[0].name);
feedback.classList.remove('d-none');

#if ($!alreadyUploadedFile)
## A file was uploaded to the server, and there was a validation error; track if the file name matches the serverside file
let matchesPreviousFile = nameField.value.trim() == "$validator.escapeHtml("$alreadyUploadedFile.getFileName()")".trim();
#else
## A file was not yet uploaded to the server
let matchesPreviousFile = false;
#end
## Compare with the name of the last selected file in the file picker
matchesPreviousFile = matchesPreviousFile || nameField.value.trim() == previousFileName.trim();
if (nameField.value == null || nameField.value.trim() == '' || matchesPreviousFile)
{
## User hasn't changed the display name; overwrite it
nameField.value = fileField.files[0].name;
}
previousFileName = fileField.files[0].name;
## Goal: update the display name field. But if the user provided their own display name, don't overwrite it
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spacing


#*
* Goal: validate the filesize.
* Note: the server doesn't accept files slightly under uploadMaxSize (default 20 MB), and the user's request is rejected.
* I suspect that validation occurs on the entire http post, and I'm unsure how to address this, but this validation is useful for most cases.
*#
#if ($!uploadMaxSize)
const maxFileSize = $!uploadMaxSize * 1024 * 1024;
const resourceAlert = document.getElementById('resourceAlert');
const submitButton = document.getElementById('saveChanges');
if (fileField.files[0].size > maxFileSize)
{
resourceAlert.innerText = "$tlang.getFormattedMessage('size.exceeded', $!uploadMaxSize)";
resourceAlert.classList.remove('d-none');
submitButton.disabled = true;
}
else
{
resourceAlert.classList.add('d-none');
resourceAlert.innerText = '';
submitButton.disabled = false;
}
#end
#if ($!alreadyUploadedFile)
## A file was uploaded to the server, and there was a validation error; track if the file name matches the serverside file
let matchesPreviousFile = nameField.value.trim() == "$validator.escapeHtml("$alreadyUploadedFile.getFileName()")".trim();

#else
## A file was not yet uploaded to the server
let matchesPreviousFile = false;
#end

## Compare with the name of the last selected file in the file picker
matchesPreviousFile = matchesPreviousFile || nameField.value.trim() == previousFileName.trim();
if (nameField.value == null || nameField.value.trim() == '' || matchesPreviousFile)
{
## User hasn't changed the display name; overwrite it
nameField.value = fileField.files[0].name;
}
previousFileName = fileField.files[0].name;

#*
* Goal: validate the filesize.
* Note: the server doesn't accept files slightly under uploadMaxSize (default 20 MB), and the user's request is rejected.
* I suspect that validation occurs on the entire http post, and I'm unsure how to address this, but this validation is useful for most cases.
*#
#if ($!uploadMaxSize)
const maxFileSize = $!uploadMaxSize * 1024 * 1024;
const resourceAlert = document.getElementById('resourceAlert');
const submitButton = document.getElementById('saveChanges');
if (fileField.files[0].size > maxFileSize)
{
resourceAlert.innerText = "$tlang.getFormattedMessage('size.exceeded', $!uploadMaxSize)";
resourceAlert.classList.remove('d-none');
submitButton.disabled = true;
}
else
{
resourceAlert.classList.add('d-none');
resourceAlert.innerText = '';
submitButton.disabled = false;
}
#end
}
else
{
feedback.classList.add('d-none');
nameField.value = '';
}
Comment on lines +242 to +246
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need else block ? when there's no file selected nothing changes and d-none is already present.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked that when I deselect a file, the message and display name do not disappear. That's why I added the else block and it works as intended.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kunaljaykam can you please review this and let me know if any changes are required?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct. I tested your pr. The else block is necessary to clear outdated file info when the file picker is opened but no new file is selected. Without it, the old file name and feedback message remain and causes console error.

I think we should re-write the whole handleFileChange function it looks messy, and include the display name field inside; fileField.files.length > 0) check as well so display name gets updates as well.


}
</script>
Loading