From 0e5fc40615025b0d22d180afd15e1533505252c4 Mon Sep 17 00:00:00 2001 From: Farhan Pathan Date: Thu, 11 Jun 2026 15:19:00 +0530 Subject: [PATCH] Molecule Identification Form Changes Doctor Duplication avoid in submited form and Edit form --- ...f382-9fbb-45ac-896b-94de9104a11b.blade.php | 172 ++++++++++++++++-- 1 file changed, 158 insertions(+), 14 deletions(-) diff --git a/resources/views/form/rapport-team4/1781090899-2cedf382-9fbb-45ac-896b-94de9104a11b.blade.php b/resources/views/form/rapport-team4/1781090899-2cedf382-9fbb-45ac-896b-94de9104a11b.blade.php index fdafc78d..5244c990 100644 --- a/resources/views/form/rapport-team4/1781090899-2cedf382-9fbb-45ac-896b-94de9104a11b.blade.php +++ b/resources/views/form/rapport-team4/1781090899-2cedf382-9fbb-45ac-896b-94de9104a11b.blade.php @@ -87,6 +87,21 @@ @php $submissions = Formhelper::getMultiformData( $form->partition, $form_id, $form->user_id); $submissions = $submissions->data->submissions; + $submissions = Formhelper::getMultiformData( + $form->partition, + $form_id, + $form->user_id + ); + + $submissions = $submissions->data->submissions; + + $submittedDoctors = collect($submissions)->map(function ($item) { + + return $item->formdata->cont_id ?? null; + + })->filter()->unique()->values()->toArray(); + + @endphp @@ -342,7 +357,7 @@ numberOfSubmission--; doctor_count--; - preventDuplicateDoctors(); + preventDuplicateDoctors(window.submittedDoctors); console.log("New Number of Submission : ", numberOfSubmission); console.log("Number of doctors : ", doctor_count); @@ -359,6 +374,29 @@ }) $('#field-legacy_code,#field-speciality').attr('readonly',true); + + window.submittedDoctors = @json($submittedDoctors); + + @if($id) + + let currentDoctors = []; + + $('select[id^="field-contact_id"]').each(function () { + + let value = $(this).val(); + + if(value){ + currentDoctors.push(value); + } + + }); + + window.submittedDoctors = + window.submittedDoctors.filter( + doctor => !currentDoctors.includes(doctor) + ); + + @endif function initializeSelect2() { @@ -372,13 +410,17 @@ placeholder: '-- Select User / Territory --' }); - $('select[id^="execution-"]').select2({ + /* $('select[id^="execution-"]').select2({ width: '100%' - }); + });*/ + $('select[id^="execution-"]').select2({ + width: '100%', + minimumResultsForSearch: Infinity + }); } initializeSelect2(); - preventDuplicateDoctors(); + preventDuplicateDoctors(window.submittedDoctors); @@ -442,6 +484,9 @@ } */ + + +/* this is its default Function function preventDuplicateDoctors() { let selectedValues = []; @@ -506,21 +551,116 @@ }); + } */ + function preventDuplicateDoctors(submittedDoctors = []) { + + let selectedDoctors = []; + + // Get currently selected doctors from form + $('select[id^="field-contact_id"]').each(function () { + + let value = $(this).val(); + + if (value) { + selectedDoctors.push(value); + } + + }); + + // Merge current + submitted doctors + let blockedDoctors = [ + ...new Set([ + ...selectedDoctors, + ...submittedDoctors + ]) + ]; + + $('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 labels + let cleanText = option.text() + .replace(' (Already Added)', '') + .replace(' (Already Submitted)', ''); + + // Keep currently selected option enabled + if ( + blockedDoctors.includes(optionValue) && + optionValue !== currentValue + ) { + + option.prop('disabled', true); + + /*if (submittedDoctors.includes(optionValue)) { + + option.text(cleanText + ' (Already Submitted)'); + + } else { + + option.text(cleanText + ' (Already Added)'); + + }*/ + if (submittedDoctors.includes(optionValue)) { + + option.text(cleanText + ' (Already Submitted)'); + + } else { + + option.text(cleanText + ' (Already Added)'); + + } + + } else { + + option.prop('disabled', false); + option.text(cleanText); + + } + + }); + + // Refresh Select2 + if (currentSelect.hasClass('select2-hidden-accessible')) { + currentSelect.select2('destroy'); + } + + currentSelect.select2({ + width: '100%', + placeholder: '-- Select Doctor --' + }); + + currentSelect.val(currentValue).trigger('change.select2'); + + }); + } $(document).on('change', 'select[id^="field-contact_id"]', function () { - let selectedOption = $(this).find(':selected'); + let selectedOption = $(this).find(':selected'); - let id = $(this).attr('id').split('-').pop(); // get doctor_count dynamically + let id = $(this).attr('id').split('-').pop(); - $('#field-legacy_code-' + id).val(selectedOption.attr('legacy_code')); - $('#field-speciality-' + id).val(selectedOption.attr('speciality')); + $('#field-legacy_code-' + id) + .val(selectedOption.attr('legacy_code')); - preventDuplicateDoctors(); - }); + $('#field-speciality-' + id) + .val(selectedOption.attr('speciality')); + + preventDuplicateDoctors(window.submittedDoctors); + +}); @@ -586,7 +726,7 @@ /* New code added for applying Search bar to dropdown in newly added doctor wrapper code and below commented code is old code */ - $('#field-contact_id-'+doctor_count).select2({ + /* $('#field-contact_id-'+doctor_count).select2({ width: '100%', placeholder: '-- Select Doctor --' @@ -602,13 +742,17 @@ minimumResultsForSearch: 0 }); - }); - preventDuplicateDoctors(); + });*/ + preventDuplicateDoctors(window.submittedDoctors); - /* $('select[id^="execution-"]').select2({ + /* $('select[id^="execution-"]').select2({ width: '100%' });*/ + $('select[id^="execution-"]').select2({ + width: '100%', + minimumResultsForSearch: Infinity + });