fix(forum): Add FormData fallback for file upload on mobile
Some checks are pending
NordaBiz Tests / Unit & Integration Tests (push) Waiting to run
NordaBiz Tests / E2E Tests (Playwright) (push) Blocked by required conditions
NordaBiz Tests / Smoke Tests (Production) (push) Blocked by required conditions
NordaBiz Tests / Send Failure Notification (push) Blocked by required conditions
Some checks are pending
NordaBiz Tests / Unit & Integration Tests (push) Waiting to run
NordaBiz Tests / E2E Tests (Playwright) (push) Blocked by required conditions
NordaBiz Tests / Smoke Tests (Production) (push) Blocked by required conditions
NordaBiz Tests / Send Failure Notification (push) Blocked by required conditions
DataTransfer API may fail on some mobile browsers, leaving fileInput empty. Added form submit interceptor that uses FormData as fallback to ensure attachments are sent. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
3a7c02efdd
commit
8de78e14a1
@ -2155,14 +2155,49 @@
|
||||
}
|
||||
|
||||
function syncFilesToInput() {
|
||||
// Create DataTransfer and add all files from Map
|
||||
const dataTransfer = new DataTransfer();
|
||||
filesMap.forEach(file => {
|
||||
dataTransfer.items.add(file);
|
||||
});
|
||||
fileInput.files = dataTransfer.files;
|
||||
try {
|
||||
const dataTransfer = new DataTransfer();
|
||||
filesMap.forEach(file => {
|
||||
dataTransfer.items.add(file);
|
||||
});
|
||||
fileInput.files = dataTransfer.files;
|
||||
} catch (e) {
|
||||
// DataTransfer not supported — form submit handler will use FormData fallback
|
||||
}
|
||||
}
|
||||
|
||||
// Intercept form submit to ensure files are sent even if DataTransfer failed
|
||||
const replyForm = dropzone.closest('form');
|
||||
replyForm.addEventListener('submit', function(e) {
|
||||
if (filesMap.size === 0) return; // no files, let form submit normally
|
||||
|
||||
// Check if fileInput actually has files (DataTransfer worked)
|
||||
if (fileInput.files && fileInput.files.length > 0) return;
|
||||
|
||||
// DataTransfer failed — manually submit with FormData
|
||||
e.preventDefault();
|
||||
const formData = new FormData(replyForm);
|
||||
// Remove empty attachments[] field
|
||||
formData.delete('attachments[]');
|
||||
// Add files from Map
|
||||
filesMap.forEach(file => {
|
||||
formData.append('attachments[]', file);
|
||||
});
|
||||
|
||||
fetch(replyForm.action, {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
}).then(resp => {
|
||||
if (resp.redirected) {
|
||||
window.location.href = resp.url;
|
||||
} else {
|
||||
window.location.reload();
|
||||
}
|
||||
}).catch(() => {
|
||||
showToast('Błąd wysyłania', 'error');
|
||||
});
|
||||
});
|
||||
|
||||
function formatFileSize(bytes) {
|
||||
if (bytes < 1024) return bytes + ' B';
|
||||
if (bytes < 1024 * 1024) return (bytes / 1024).toFixed(1) + ' KB';
|
||||
|
||||
Loading…
Reference in New Issue
Block a user