Commit d53b7153 by Owen Ryan Ang

file picker code adjustment

parent 89892ed8
...@@ -1163,6 +1163,7 @@ const inputFileUpload = (key, validation) => { ...@@ -1163,6 +1163,7 @@ const inputFileUpload = (key, validation) => {
// Add an event listener to handle when a file is selected // Add an event listener to handle when a file is selected
input.addEventListener('change', (event) => { input.addEventListener('change', (event) => {
const file = event.target.files[0]; const file = event.target.files[0];
console.log(file)
if (file) { if (file) {
// Create hidden inputs for fname and file content // Create hidden inputs for fname and file content
...@@ -1256,30 +1257,38 @@ const inputFileUpload = (key, validation) => { ...@@ -1256,30 +1257,38 @@ const inputFileUpload = (key, validation) => {
} }
} }
else { else {
// Display the filename only for unsupported file types const reader = new FileReader();
filename.textContent = file.name; reader.readAsDataURL(file);
filename.style.display = 'inline'; reader.onload = (e) => {
document.getElementById(`${key}_buttonsContainer-video`).style.display = 'none'; // Display the filename only for unsupported file types
x.style.display = 'block'; const fileInput = document.getElementById(`${key}_attachedMedia`);
x.style.position = 'absolute'; const fullPath = fileInput.value;
console.log(fileInput);
// Set the hidden inputs for filename and empty file content // const filename = fullPath.split('\\').pop().split('/').pop();
hiddenFnameInput.value = file.name; filename.textContent = fullPath.split('\\').pop().split('/').pop();
hiddenFnameInput.display = ''; filename.style.display = 'inline';
hiddenFileContentInput.value = ''; // Empty content for unsupported file types document.getElementById(`${key}_buttonsContainer-video`).style.display = 'none';
hiddenFileContentInput.display = ''; x.style.display = 'block';
x.style.position = 'absolute';
// Remove the file on 'x' click
document.getElementById(`${key}_x`).addEventListener('click', () => { // Set the hidden inputs for filename and empty file content
filename.style.display = 'none'; hiddenFnameInput.value = fullPath.split('\\').pop().split('/').pop();
document.getElementById(`${key}_buttonsContainer-video`).style.display = 'flex'; hiddenFnameInput.display = '';
input.value = ''; hiddenFileContentInput.value = e.target.result;
x.style.display = 'none'; hiddenFileContentInput.display = '';
// Clear the hidden fields // Remove the file on 'x' click
container2.removeChild(hiddenFnameInput); document.getElementById(`${key}_x`).addEventListener('click', () => {
container2.removeChild(hiddenFileContentInput); filename.style.display = 'none';
}); document.getElementById(`${key}_buttonsContainer-video`).style.display = 'flex';
input.value = '';
x.style.display = 'none';
// Clear the hidden fields
container2.removeChild(hiddenFnameInput);
container2.removeChild(hiddenFileContentInput);
});
}
} }
} }
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment