@@ -1080,6 +1080,10 @@ function changeUnauthorizedPage(direction) {
10801080
10811081// ==================== PERSONNEL MANAGEMENT ====================
10821082
1083+ // Global flags to prevent multiple event listener attachments and submissions
1084+ let personnelFormInitialized = false ;
1085+ let isSubmittingPersonnel = false ;
1086+
10831087// Department/Sub-department configuration
10841088// Note: Departments are now hardcoded in HTML for 1BIP military structure
10851089// Sub-departments are manually entered (no cascade)
@@ -1129,18 +1133,21 @@ function setupPhotoPreview() {
11291133
11301134// Handle personnel form submission
11311135async function setupPersonnelForm ( ) {
1136+ // Prevent multiple event listener attachments
1137+ if ( personnelFormInitialized ) {
1138+ console . log ( 'Personnel form already initialized, skipping duplicate setup' ) ;
1139+ return ;
1140+ }
1141+
11321142 const form = document . getElementById ( 'addPersonnelForm' ) ;
11331143 const messageDiv = document . getElementById ( 'formMessage' ) ;
11341144
1135- // Submission guard flag to prevent multiple simultaneous submissions
1136- let isSubmitting = false ;
1137-
11381145 if ( form ) {
11391146 form . addEventListener ( 'submit' , async function ( e ) {
11401147 e . preventDefault ( ) ;
11411148
1142- // Prevent multiple simultaneous submissions
1143- if ( isSubmitting ) {
1149+ // Prevent multiple simultaneous submissions (using global flag)
1150+ if ( isSubmittingPersonnel ) {
11441151 console . log ( 'Submission already in progress, ignoring duplicate request' ) ;
11451152 return ;
11461153 }
@@ -1153,7 +1160,7 @@ async function setupPersonnelForm() {
11531160 }
11541161
11551162 // Set submission flag and show loading state
1156- isSubmitting = true ;
1163+ isSubmittingPersonnel = true ;
11571164 const submitBtn = form . querySelector ( 'button[type="submit"]' ) ;
11581165 const originalText = submitBtn . textContent ;
11591166 submitBtn . disabled = true ;
@@ -1200,11 +1207,15 @@ async function setupPersonnelForm() {
12001207 showFormMessage ( '❌ Erreur lors de l\'ajout du personnel' , 'error' ) ;
12011208 } finally {
12021209 // Reset submission flag and button state
1203- isSubmitting = false ;
1210+ isSubmittingPersonnel = false ;
12041211 submitBtn . disabled = false ;
12051212 submitBtn . textContent = originalText ;
12061213 }
12071214 } ) ;
1215+
1216+ // Mark as initialized to prevent duplicate event listeners
1217+ personnelFormInitialized = true ;
1218+ console . log ( 'Personnel form initialized successfully' ) ;
12081219 }
12091220}
12101221
0 commit comments