diff --git a/resources/views/form/rapport-titans/1794825526-5d6e4128-2bf1-42e9-bbe2-2480c1724c6c.blade.php b/resources/views/form/rapport-titans/1794825526-5d6e4128-2bf1-42e9-bbe2-2480c1724c6c.blade.php
index 4dfceb5c..b041734e 100644
--- a/resources/views/form/rapport-titans/1794825526-5d6e4128-2bf1-42e9-bbe2-2480c1724c6c.blade.php
+++ b/resources/views/form/rapport-titans/1794825526-5d6e4128-2bf1-42e9-bbe2-2480c1724c6c.blade.php
@@ -364,7 +364,7 @@
// $(mslField).parent().hide();
// })
- $('#field-no_of_attendees').on('change',function(){
+ /* $('#field-no_of_attendees').on('change',function(){
let qtyValue=parseInt($(this).val());
$('#doctor_msl_wrapper').html('')
for(let i = 1; i <= qtyValue; i++) {
@@ -377,7 +377,180 @@
`)
}
- })
+ }) */
+
+
+
+// Generate Doctor Dropdowns based on No. of Attendees
+ $('#field-no_of_attendees').on('change', function () {
+
+ let qtyValue = parseInt($(this).val()) || 0;
+
+ $('#doctor_msl_wrapper').html('');
+
+ for (let i = 1; i <= qtyValue; i++) {
+
+ let doctorHtml = `
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ `;
+
+ $('#doctor_msl_wrapper').append(doctorHtml);
+
+ let select = $('#field-contact_id_' + i);
+
+ // Load doctors from API response
+ contacts.forEach(function (itm) {
+
+ if (!itm || !itm.value || !itm.display) {
+ return;
+ }
+
+ let doctorValue = String(itm.value);
+ let doctorName = String(itm.display);
+
+ let legacyCode = '';
+
+ if (itm.contact) {
+ legacyCode = itm.contact.legacy_code || itm.contact.msl_code || '';
+ } else {
+ legacyCode = itm.legacy_code || itm.msl_code || '';
+ }
+
+ let valCheck = doctorValue.trim().toLowerCase();
+ let textCheck = doctorName.trim().toLowerCase();
+
+ let isAlreadySubmitted =
+ submittedDoctors.includes(valCheck) ||
+ submittedDoctors.includes(textCheck);
+
+ let displayText = doctorName;
+
+ if (isAlreadySubmitted) {
+ displayText += ' - Already Added';
+ }
+
+ let option = $('')
+ .val(doctorValue)
+ .text(displayText)
+ .attr('data-legacy-code', legacyCode)
+ .prop('disabled', isAlreadySubmitted);
+
+ select.append(option);
+ });
+
+ // Initialize Select2
+ select.select2({
+ width: '100%',
+ placeholder: '-- Select Doctor --',
+ allowClear: true
+ });
+
+ }
+
+ });
+
+// When Doctor is selected, populate P Code
+ $(document).on('change', '.doctor-dropdown', function () {
+
+ let selectedOption = $(this).find(':selected');
+
+ let legacyCode = selectedOption.attr('data-legacy-code') || '';
+
+ let selectId = $(this).attr('id');
+
+ let match = selectId.match(/^field-contact_id_(\d+)$/);
+
+ if (match) {
+
+ let index = match[1];
+
+ $('#field-msl_code_' + index).val(legacyCode);
+
+ }
+
+ // Prevent duplicate doctor selection
+ let selectedValues = [];
+
+ $('.doctor-dropdown').each(function () {
+
+ let value = $(this).val();
+
+ if (value) {
+ selectedValues.push(String(value));
+ }
+
+ });
+
+ $('.doctor-dropdown').each(function () {
+
+ let currentSelect = $(this);
+
+ let currentValue = String(currentSelect.val() || '');
+
+ currentSelect.find('option').each(function () {
+
+ let option = $(this);
+
+ let optionValue = String(option.val() || '');
+
+ if (!optionValue) {
+ return;
+ }
+
+ if (
+ selectedValues.includes(optionValue) &&
+ optionValue !== currentValue
+ ) {
+ option.prop('disabled', true);
+ } else if (
+ !option.text().includes('Already Added')
+ ) {
+ option.prop('disabled', false);
+ }
+
+ });
+
+ currentSelect.trigger('change.select2');
+
+ });
+
+ });
+
function hideDoctorFields (){
docNameFields.forEach((docField, index) => {