1// validationManager.js 2(function($, FW) { 3 'use strict'; 4 5 FW.ValidationManager = (function() { 6 function init() { 7 $('.form-container').on('input change', 'input, select, textarea', function() { 8 validateField($(this)); 9 }); 10 } 11 12 function validateCurrentStep(callback) { 13 const currentStepId = getCurrentStepId(); 14 let isValid = true; 15 $(`#${currentStepId} input, #${currentStepId} select, #${currentStepId} textarea`).each(function() { 16 if (!validateField($(this))) { 17 isValid = false; 18 } 19 }); 20 if (isValid) { 21 callback(); 22 } 23 } 24 25 function validateField($field) { 26 const fieldType = $field.attr('type'); 27 const value = $field.val(); 28 let isValid = true; 29 $field.removeClass('error'); 30 $field.next('.error-message').text(''); 31 32 if ($field.prop('required')) { 33 if (fieldType === 'checkbox' || fieldType === 'radio') { 34 if (!$field.is(':checked')) { 35 isValid = false; 36 showError($field, 'Ce champ est requis.'); 37 } 38 } else { 39 if (!value.trim()) { 40 isValid = false; 41 showError($field, 'Ce champ est requis.'); 42 } 43 } 44 } 45 46 if ($field.attr('type') === 'email' && value.trim()) { 47 const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; 48 if (!emailRegex.test(value)) { 49 isValid = false; 50 showError($field, 'Veuillez entrer une adresse e-mail valide.'); 51 } 52 } 53 54 if ($field.attr('minlength')) { 55 const minLength = parseInt($field.attr('minlength'), 10); 56 if (value.trim().length < minLength) { 57 isValid = false; 58 showError($field, `Veuillez entrer au moins ${minLength} caractères.`); 59 } 60 } 61 return isValid; 62 } 63 64 function showError($field, message) { 65 $field.addClass('error'); 66 $field.next('.error-message').show(); 67 $field.next('.error-message').text(message); 68 } 69 70 function getCurrentStepId() { 71 return $('.form-container .step--active').attr('id'); 72 } 73 74 return { 75 init, 76 validateCurrentStep 77 }; 78 })(); 79 80 $(document).ready(function() { 81 FormWizard.ValidationManager.init(); 82 }); 83})(jQuery, window.FormWizard = window.FormWizard || {});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.