From 3b675acae31f77ec0d98a3ba0a135b6f9c553119 Mon Sep 17 00:00:00 2001 From: zeeshan Date: Fri, 9 Oct 2026 16:43:40 +0530 Subject: [PATCH] Team 4 (Mother Forum) --- ...2f9a-fe45-4b16-843a-224f07ed0d7b.blade.php | 217 ++++++++++++------ 1 file changed, 147 insertions(+), 70 deletions(-) diff --git a/resources/views/form/rapport-team4/1791539482-b06c2f9a-fe45-4b16-843a-224f07ed0d7b.blade.php b/resources/views/form/rapport-team4/1791539482-b06c2f9a-fe45-4b16-843a-224f07ed0d7b.blade.php index 1174eae4..be730a0f 100644 --- a/resources/views/form/rapport-team4/1791539482-b06c2f9a-fe45-4b16-843a-224f07ed0d7b.blade.php +++ b/resources/views/form/rapport-team4/1791539482-b06c2f9a-fe45-4b16-843a-224f07ed0d7b.blade.php @@ -89,27 +89,72 @@ @case('textarea') @break - + {{-- @case('dropdown') + @php + $isContact = str_starts_with($question->code, 'contact_id'); + $options = collect($question->options)->sortBy('display', SORT_NATURAL | SORT_FLAG_CASE); + @endphp + + + @break --}} + + @case('dropdown') @php $isContact = str_starts_with($question->code, 'contact_id'); + + // जर options collection किंवा array असेल तर display field नुसार alphabetize करा $options = collect($question->options)->sortBy('display', SORT_NATURAL | SORT_FLAG_CASE); @endphp - {{-- $isContact असल्यास data-toggle="select2" देऊ नका, जेणेकरून AJAX लोड होण्यापूर्वी Select2 चुकीच्या options सह bind होणार नाही --}} - required == 'yes' ? 'required' : '' }}> - @if(!$isContact) - @foreach ($options as $option) - - @endforeach - @endif + @elseif(!$isContact) + + @endif + @endforeach @break - @case('checkbox') @foreach($question->options as $option)
@@ -220,7 +265,9 @@ }); }) ).then(function() { - + // All contacts loaded for each hierarchy + // Example usage: console.log(contacts); + // Filter out contacts where value == 'sample' contacts = contacts.filter(function(itm) { return itm.value !== 'sample' && itm.contact && itm.contact.type === 'doctor' }); contacts.sort(function(a, b) { @@ -231,7 +278,18 @@ // Loop through contacts and append options to select elements whose id starts with 'field-contact_id' // We assume contact_id fields may be suffixed, e.g. field-contact_id_1, field-contact_id, etc. - + function applySelect2ToDoctorDropdowns() { + $("select[id^='field-contact_id']").each(function () { + var select = $(this); + // Avoid re-initializing select2 + if (select.data("select2")) return; + select.select2({ + width: "100%", + placeholder: "-- Select --", + allowClear: true + }); + }); + } $('input[id^="field-msl_code"], input[id^="field-speciality"]').prop('readonly', true); @@ -251,10 +309,8 @@ var currentSelect = $(this); var currentVal = currentSelect.val() ? String(currentSelect.val()) : ""; - currentSelect.find("option").prop("disabled", false); - selectedValues.forEach(function (v) { if (v && v !== currentVal) { currentSelect @@ -265,79 +321,95 @@ if (currentSelect.hasClass("select2-hidden-accessible")) { - currentSelect.trigger('change.select2'); + + currentSelect.select2({ + width: "100%", + placeholder: "-- Select --", + allowClear: true + }); } }); - } + } + $("select[id^='field-contact_id']").each(function() { - var select = $(this); - var savedValue = select.attr('data-selected') || select.data('selected') || select.val() || ''; + var select = $(this); + // Clear previous options - // जुने select2 नष्ट करा (जर आधी लागले असेल तर) - if (select.hasClass("select2-hidden-accessible")) { - select.select2('destroy'); - } + var savedValue = select.attr('data-selected') || select.data('selected') || select.val() || ''; + select.empty(); - // Options रीसेट करा - select.empty(); - select.append($("").attr("value", '').text('-- Select --')); + // Add a default 'Select' option + select.append( + $("") + .attr("value", '') + .text('-- Select --') + ); + // Append options from contacts + contacts.forEach(function(itm) { + var option = $("") + .attr("value", itm.value) + .text(itm.display); + - // नवीन contacts append करा - contacts.forEach(function(itm) { - var option = $("").attr("value", itm.value).text(itm.display); - if (itm.contact && itm.contact.msl_code) { - option.attr("msl_code", itm.contact.msl_code); - } - if (itm.contact && itm.contact.speciality) { - option.attr("speciality", itm.contact.speciality); - } + // If doctor options have extra attributes + if (itm.contact && itm.contact.msl_code) { + option.attr("msl_code", itm.contact.msl_code); + } + if (itm.contact && itm.contact.speciality) { + option.attr("speciality", itm.contact.speciality); + } - if (savedValue && String(savedValue) === String(itm.value)) { - option.prop('selected', true); - } + if (savedValue && String(savedValue) === String(itm.value)) { + option.prop('selected', true); + } - select.append(option); - }); + select.append(option); + }); - // Event listener bind करा - select.off('change').on('change', function () { - var selected = $(this).find(':selected'); - var selectId = $(this).attr('id'); - var match = selectId.match(/^field-contact_id(_\d+)?$/); - var suffix = match && match[1] ? match[1] : ''; + // For each select element, add a change event handler to populate `msl_code` and `speciality` + // We assume dropdowns and targets follow the pattern: + // - select: field-contact_id_1, field-contact_id_2, ..., field-contact_id + // - result: field-msl_code_1, field-speciality_1, etc. - var mslCodeField = $('#field-msl_code' + suffix); - var specialityField = $('#field-speciality' + suffix); + // Remove any old event handlers first to prevent duplicate bindings + select.off('change').on('change', function () { + var selected = $(this).find(':selected'); + + var selectId = $(this).attr('id'); // e.g., field-contact_id_1 + // Extract the suffix (e.g., _1 or empty) + var match = selectId.match(/^field-contact_id(_\d+)?$/); + var suffix = match && match[1] ? match[1] : ''; - if (mslCodeField.length) { - mslCodeField.val(selected.attr('msl_code') || ''); - } - if (specialityField.length) { - specialityField.val(selected.attr('speciality') || ''); - } + // Build the target msl_code and speciality field ids + var mslCodeField = $('#field-msl_code' + suffix); + var specialityField = $('#field-speciality' + suffix); - enforceUniqueDoctorSelections(); - }); + if (mslCodeField.length) { + mslCodeField.val(selected.attr('msl_code') || ''); + } + if (specialityField.length) { + specialityField.val(selected.attr('speciality') || ''); + } - if (savedValue) { - select.val(savedValue); - } + // Prevent selecting the same doctor across multiple dropdowns + enforceUniqueDoctorSelections(); + }); - // Select2 पुन्हा इनिशिअलाइझ करा - select.select2({ - width: "100%", - placeholder: "-- Select --", - allowClear: true - }); - }); + if (savedValue) { + select.val(savedValue).trigger('change'); + } - // 3. Unique selection लागू करा आणि लोडर बंद करा - enforceUniqueDoctorSelections(); - $("#pageloader").fadeOut(); -}); - + + }); + + // Ensure unique selection is enforced after initial render + enforceUniqueDoctorSelections(); + // Enable search on doctor dropdowns + applySelect2ToDoctorDropdowns(); + $("#pageloader").fadeOut(); + }); @@ -390,7 +462,12 @@ var plandateField = document.getElementById('field-record_date'); - + plandateField.setAttribute('min', "2026-10-09"); + plandateField.setAttribute('max', "2026-10-09"); + + plandateField.value="2026-10-09"; + + $('#field-record_date').prop('readonly', true); });