1jQuery(document).ready(function ($) { 2 3 // Vérifie qu'il y a au moins un champ participant sur la page 4 const hasParticipants = $('[class*="participant-"]').length > 0; 5 let maxParticipants = 0; 6 7 function getMaxConfigured() { 8 let max = 0; 9 $('[class*="participant-"]').closest('.gfield').each(function () { 10 const classes = $(this).attr('class') || ''; 11 const match = classes.match(/participant-(\d+)/); 12 if ( match ) { 13 max = Math.max(max, parseInt(match[1])); 14 } 15 }); 16 return max; 17 } 18 19 function updateParticipants( qty, clearValues ) { 20 if ( ! hasParticipants ) return; 21 22 const effective = maxParticipants > 0 ? Math.min(qty, maxParticipants) : qty; 23 const maxConfigured = getMaxConfigured(); 24 25 for ( let i = 1; i <= maxConfigured; i++ ) { 26 const fields = $(`.participant-${i}`).closest('.gfield'); 27 if ( i <= effective ) { 28 fields.show(); 29 } else { 30 fields.hide(); 31 if ( clearValues ) { 32 fields.find('input, textarea, select').val(''); 33 } 34 } 35 } 36 } 37 38 // Quand un créneau est sélectionné â met à jour maxParticipants 39 $(document).on('change', 'input[type="radio"][data-max]', function () { 40 maxParticipants = parseInt($(this).data('max')) || 0; 41 const qty = parseInt($('.gf-qty').val()) || 0; 42 updateParticipants( qty, true ); 43 }); 44 45 // Quand la date change â reset maxParticipants 46 $(document).on('change', '.gf-date-value', function () { 47 maxParticipants = 0; 48 updateParticipants( 0, true ); 49 }); 50 51 // Quand la quantité change 52 $(document).on('input change blur', '.gf-qty', function () { 53 const qty = parseInt($(this).val()) || 0; 54 updateParticipants( qty, true ); 55 }); 56 57 // Après re-rendu Gravity Forms 58 $(document).on('gform_post_render', function () { 59 const qty = parseInt($('.gf-qty').val()) || 0; 60 updateParticipants( qty, false ); 61 }); 62 63 // Après restauration AJAX (depuis restoreState dans inventory-slots.js) 64 $(document).on('gf-qty-restore', '.gf-qty', function (e, qty) { 65 maxParticipants = 0; 66 updateParticipants( qty, false ); 67 }); 68 69 // Au submit â vider les champs participants cachés pour ne pas les envoyer 70 $('form').on('submit', function () { 71 const maxConfigured = getMaxConfigured(); 72 const effective = maxParticipants > 0 73 ? Math.min(parseInt($('.gf-qty').val()) || 0, maxParticipants) 74 : parseInt($('.gf-qty').val()) || 0; 75 76 for ( let i = effective + 1; i <= maxConfigured; i++ ) { 77 $(`.participant-${i}`).closest('.gfield').find('input, textarea, select').val(''); 78 } 79 }); 80 81 // --- Initialisation --- 82 // Si une restauration AJAX est en attente, on ne cache rien tout de suite. 83 if ( hasParticipants ) { 84 const hasRestorePending = $('.gf-inventory-date[data-restore-date]').filter(function () { 85 return $(this).data('restore-date') !== ''; 86 }).length > 0; 87 88 if ( ! hasRestorePending ) { 89 const initialQty = parseInt($('.gf-qty').val()) || 0; 90 updateParticipants( initialQty, false ); 91 } 92 } 93 94});
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.