<script>
    //Ajouter Profil
    //Add file name uploaded on label
    var eleve_id = 0;
    var classe_libelle = "";
    var classe_slug = "";

    const fileInput = document.querySelector('#input-profil input[type=file]');
    fileInput.onchange = () => {
        if (fileInput.files.length > 0) {
            const fileName = document.querySelector('.profil_file_name');
            fileName.textContent = fileInput.files[0].name;
        }
    }
    //Add validation method filesize()
    $.validator.addMethod('filesize', function(value, element, param) {
        return this.optional(element) || (element.files[0].size <= param)
    }, 'File size must be less than {0}');

    $('#btn_submit_profil').on('click', function(e) {
        $('#form_profil').validate({
            rules: {
                profil: {
                    required: true,
                    extension: "jpg|jpeg",
                    filesize: 1000000,
                },
            },
            messages: {
                profil: {
                    required: "Aucun fichier choisi",
                    extension: "Ce fichier n'est pas une image",
                    filesize: "Fichier très lourd",
                },
            },
        })
    });
</script>
