From ba46a82103d4d123714a9e2734f4c5c8d4ba65ab Mon Sep 17 00:00:00 2001 From: zeeshan Date: Sat, 21 Nov 2026 18:22:52 +0530 Subject: [PATCH] Team2 (Lung Care Programme) Remove Index --- ...ffaa-1b76-40c8-800b-6b2d3c801016.blade.php | 101 +++++++++++++++++- 1 file changed, 99 insertions(+), 2 deletions(-) diff --git a/resources/views/form/rapport-team2/1794811995-cd07ffaa-1b76-40c8-800b-6b2d3c801016.blade.php b/resources/views/form/rapport-team2/1794811995-cd07ffaa-1b76-40c8-800b-6b2d3c801016.blade.php index 39869f7f..c3387c46 100644 --- a/resources/views/form/rapport-team2/1794811995-cd07ffaa-1b76-40c8-800b-6b2d3c801016.blade.php +++ b/resources/views/form/rapport-team2/1794811995-cd07ffaa-1b76-40c8-800b-6b2d3c801016.blade.php @@ -327,6 +327,8 @@ const tmHierarchies = @json(isset($form->users) ? collect($form->users)->pluck('hierarchy_id')->filter()->unique()->values() : []); let doctor_count = 0; + let allDoctorsList = []; + function initializeSelect2(element) { const $element = $(element); @@ -559,6 +561,8 @@ return String(a.display || '').localeCompare(String(b.display || ''), 'en', { sensitivity: 'base' }); }); + allDoctorsList = allDoctors; + const $doctorSelect = $('#field-contact_id'); const preselectedDoctorId = String($doctorSelect.attr('data-preselected') || ''); @@ -606,7 +610,7 @@ loadAllTmDoctors(); // Add another doctor wrapper. The first wrapper is already present in the form. - $('#adddoctor-btn').on('click', function () { + /* $('#adddoctor-btn').on('click', function () { if ($('.doctor-wrapper').length >= 5) return; const doctorOptions = $('#field-contact_id').html(); @@ -679,11 +683,103 @@ initializeExecutionSelects(); preventDuplicateDoctors(); + if ($('.doctor-wrapper').length >= 5) { + $('#adddoctor-btn').hide(); + } + }); */ + + $('#adddoctor-btn').on('click', function () { + if ($('.doctor-wrapper').length >= 5) return; + + doctor_count++; + + + let doctorOptionsHtml = ''; + allDoctorsList.forEach(function (doctor) { + const contact = doctor.contact || {}; + const msl = contact.msl_code || contact.legacy_code || ''; + const spec = contact.speciality || ''; + doctorOptionsHtml += ``; + }); + + const empty_doctor = ` +
+ + @foreach($questions as $question) + @if(in_array($question->code, ["record_date", "select_rxber_type"])) + @continue; + @endif +
+ + @switch($question->type) + @case('hidden') + + @break + @case('text') + @case('file') + @case('email') + @case('tel') + @case('date') + required == 'yes'?'required':''}} value="{{isset($question->value)?$question->value:''}}"> + @break + @case('number') + required == 'yes'?'required':''}} value="{{isset($question->value)?$question->value:0}}"> + @break + @case('dropdown') + + @break + @case('checkbox') + @foreach($question->options as $option) +
+ + +
+ @endforeach + @break + @endswitch +
+ @endforeach +
`; + + $('#doctor-group-wrapper').append(empty_doctor); + + const $newDoctorSelect = $('#field-contact_id-' + doctor_count); + initializeSelect2($newDoctorSelect); + $('#field-msl_code-' + doctor_count + ', #field-speciality-' + doctor_count).attr('readonly', true); + initializeExecutionSelects(); + preventDuplicateDoctors(); + if ($('.doctor-wrapper').length >= 5) { $('#adddoctor-btn').hide(); } }); + + +function reindexDoctorWrappers() { + $('.doctor-wrapper').each(function (index) { + $(this).find('[name]').each(function () { + const currentName = $(this).attr('name'); + + const updatedName = currentName.replace(/\[\d+\]/, '[' + index + ']'); + $(this).attr('name', updatedName); + }); + }); +} + // Remove a dynamically added doctor wrapper without reusing its element IDs. $(document).on('click', '.btn-remove', function () { doctor_count--; @@ -692,6 +788,7 @@ if ($(this).hasClass('select2-hidden-accessible')) $(this).select2('destroy'); }); $wrapper.remove(); + reindexDoctorWrappers(); preventDuplicateDoctors(); if ($('.doctor-wrapper').length < 5) $('#adddoctor-btn').show(); }); @@ -730,7 +827,7 @@ alert('You must select exactly 5 doctors. Currently selected: ' + selectedDoctorCount); return; } - + reindexDoctorWrappers(); $('#pageloader').fadeIn(); $.ajax({ type: 'POST',