From fd76dcda754f028fa56c35a90f8b3c2740b30906 Mon Sep 17 00:00:00 2001 From: zeeshan Date: Thu, 5 Nov 2026 12:57:25 +0530 Subject: [PATCH] Team 3 (Levoswitch Enrollment) --- ...7206-8dba-471e-b08f-deece5d36d11.blade.php | 115 ++++++++---------- 1 file changed, 52 insertions(+), 63 deletions(-) diff --git a/resources/views/form/rapport-team3/1793772514-e8e67206-8dba-471e-b08f-deece5d36d11.blade.php b/resources/views/form/rapport-team3/1793772514-e8e67206-8dba-471e-b08f-deece5d36d11.blade.php index 8f0b5431..43937f46 100644 --- a/resources/views/form/rapport-team3/1793772514-e8e67206-8dba-471e-b08f-deece5d36d11.blade.php +++ b/resources/views/form/rapport-team3/1793772514-e8e67206-8dba-471e-b08f-deece5d36d11.blade.php @@ -397,70 +397,12 @@ + + /* function preventDuplicateDoctors() { let selectedValues = []; - // Get all selected doctor values - $('select[id^="field-contact_id"]').each(function () { - - let value = $(this).val(); - - if (value) { - selectedValues.push(value); - } - - }); - - // Apply duplicate prevention - $('select[id^="field-contact_id"]').each(function () { - - let currentSelect = $(this); - let currentValue = currentSelect.val(); - - currentSelect.find('option').each(function () { - - let option = $(this); - let optionValue = option.val(); - - if (!optionValue) return; - - // Remove old text - let cleanText = option.text().replace(' (Already Added)', ''); - - if ( - selectedValues.includes(optionValue) && - optionValue !== currentValue - ) { - - option.prop('disabled', true); - option.text(cleanText + ' (Already Added)'); - - } else { - - option.prop('disabled', false); - option.text(cleanText); - - } - - }); - - // 🔥 IMPORTANT - currentSelect.select2('destroy'); - - currentSelect.select2({ - width: '100%', - placeholder: '-- Select Doctor --' - }); - - }); - - } */ - - function preventDuplicateDoctors() { - - let selectedValues = []; - // Collect selected values $('select[id^="field-contact_id"]').each(function () { @@ -521,8 +463,47 @@ }); - } + } */ + function preventDuplicateDoctors() { + let selectedValues = []; + + // Collect all selected doctor IDs (ignoring empty selections) + $('select[id^="field-contact_id"]').each(function () { + let val = $(this).val(); + if (val) { + selectedValues.push(val); + } + }); + + // Update options for each select + $('select[id^="field-contact_id"]').each(function () { + let currentSelect = $(this); + let currentValue = currentSelect.val(); + + currentSelect.find('option').each(function () { + let option = $(this); + let optionValue = option.val(); + + if (!optionValue) return; + + // Clean previously appended text + let originalText = option.text().replace(' (Already Added)', '').trim(); + + // If selected in another dropdown, disable it and add indicator + if (selectedValues.includes(optionValue) && optionValue !== currentValue) { + option.prop('disabled', true); + option.text(originalText + ' (Already Added)'); + } else { + option.prop('disabled', false); + option.text(originalText); + } + }); + + // Trigger change to update Select2 without destroying entire DOM binding + currentSelect.trigger('change.select2'); + }); +} $(document).on('change', 'select[id^="field-contact_id"]', function () { @@ -721,12 +702,20 @@ console.log(hierarchy) }) - + var isEditMode = @json((bool)$id); $('#report-form').on('submit', function(event) { event.preventDefault(); - if (numberOfSubmission !=9) { + /* if (numberOfSubmission !=9) { alert(`You must submit 10 Doctors for Levoswitch , Current Doctors : ${numberOfSubmission+1}`); return; + } */ + + if (!isEditMode) { + let currentTotal = $('.doctor-wrapper').length; + if (currentTotal !== 10) { + alert(`You must submit 10 Doctors for Levoswitch, Current Doctors: ${currentTotal}`); + return; + } }