Commit d53b7153 by Owen Ryan Ang

file picker code adjustment

parent 89892ed8
......@@ -1163,6 +1163,7 @@ const inputFileUpload = (key, validation) => {
// Add an event listener to handle when a file is selected
input.addEventListener('change', (event) => {
const file = event.target.files[0];
console.log(file)
if (file) {
// Create hidden inputs for fname and file content
......@@ -1256,30 +1257,38 @@ const inputFileUpload = (key, validation) => {
}
}
else {
// Display the filename only for unsupported file types
filename.textContent = file.name;
filename.style.display = 'inline';
document.getElementById(`${key}_buttonsContainer-video`).style.display = 'none';
x.style.display = 'block';
x.style.position = 'absolute';
// Set the hidden inputs for filename and empty file content
hiddenFnameInput.value = file.name;
hiddenFnameInput.display = '';
hiddenFileContentInput.value = ''; // Empty content for unsupported file types
hiddenFileContentInput.display = '';
// Remove the file on 'x' click
document.getElementById(`${key}_x`).addEventListener('click', () => {
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);
});
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = (e) => {
// Display the filename only for unsupported file types
const fileInput = document.getElementById(`${key}_attachedMedia`);
const fullPath = fileInput.value;
console.log(fileInput);
// const filename = fullPath.split('\\').pop().split('/').pop();
filename.textContent = fullPath.split('\\').pop().split('/').pop();
filename.style.display = 'inline';
document.getElementById(`${key}_buttonsContainer-video`).style.display = 'none';
x.style.display = 'block';
x.style.position = 'absolute';
// Set the hidden inputs for filename and empty file content
hiddenFnameInput.value = fullPath.split('\\').pop().split('/').pop();
hiddenFnameInput.display = '';
hiddenFileContentInput.value = e.target.result;
hiddenFileContentInput.display = '';
// Remove the file on 'x' click
document.getElementById(`${key}_x`).addEventListener('click', () => {
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