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

[BO - Ajout photos situation] Ne pas uploader les photos aux formats non pris en charge #2451

Merged
merged 2 commits into from
Apr 15, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,17 @@ function initializeUploadModal(
}

function typeValidation(file) {
let splitType = file.type.split('/')[0]
let acceptedType = fileSelectorInput.getAttribute('accept').split('/')[0];
let acceptedType = fileSelectorInput.getAttribute('accept');
if (acceptedType == '*') {
return true
}
if (acceptedType == splitType) {
let acceptedTypes = acceptedType.split(',').map((type) => type.trim())
if (acceptedTypes.includes(file.type)) {
return true
}
let div = document.createElement('div')
div.classList.add('fr-alert', 'fr-alert--error', 'fr-alert--sm')
div.innerHTML = `Le type du fichier ${file.name} n'est pas accepté (acceptés : ".jpg", ".png", ".gif")`;
div.innerHTML = `Impossible d'ajouter le fichier "${file.name}" car le format n'est pas pris en charge. Veuillez sélectionner une photo au format JPG, PNG ou GIF.`;
listContainer.prepend(div)
return false;
}
Expand Down Expand Up @@ -331,7 +331,8 @@ function initializeUploadModal(
if (fileType == 'photo') {
modal.dataset.fileType = 'photo'
modal.querySelector('.type-photo').classList.remove('fr-hidden')
fileSelectorInput.setAttribute('accept', 'image/*')
fileSelectorInput.setAttribute('accept', 'image/jpeg,image/png,image/gif')

} else {
modal.dataset.fileType = 'document'
modal.querySelector('.type-document').classList.remove('fr-hidden')
Expand Down
Loading