feat(instructeurs import): display submit button only if file uploaded

This commit is contained in:
Eric Leroy-Terquem 2024-09-30 10:14:27 +02:00
parent ec7aea50b3
commit 7af934daf5
No known key found for this signature in database
GPG key ID: 53D8FAECEF207605
2 changed files with 23 additions and 2 deletions

View file

@ -0,0 +1,21 @@
import { Controller } from '@hotwired/stimulus';
import { enable, disable } from '@utils';
export class EnableSubmitIfUploadedController extends Controller {
connect() {
const fileInput = document.querySelector(
'input[type="file"]'
) as HTMLInputElement;
const submitButton = document.getElementById(
'submit-button'
) as HTMLButtonElement;
fileInput.addEventListener('change', function () {
if (fileInput.files && fileInput.files.length > 0) {
enable(submitButton);
} else {
disable(submitButton);
}
});
}
}