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 e2b2119c..f5c61c03 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 @@ -6,11 +6,10 @@ - - -
+
processing...
+
@@ -48,7 +47,7 @@ @endphp - @if(count($submissions) ==0 || !empty($id) ) + @if(count($submissions) ==0)
@@ -57,20 +56,7 @@ @if($id) @endif - {{-- @if(isset($form->manager_can_submit) && $form->manager_can_submit == true) -
- - - -
- @endif --}} - @foreach($questions as $question)
@@ -90,26 +76,21 @@ @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 - - required == 'yes' ? 'required' : '' }}> @foreach ($question->options as $option) - @if($isContact && isset($option->contact->type) && $option->contact->type == 'doctor' ) + @if($question->code == 'contact_id' && isset($option->contact->type) && $option->contact->type == 'doctor' ) - @elseif(!$isContact) + @elseif($question->code != 'contact_id') @@ -118,44 +99,9 @@ @endforeach + - @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 - - -@break + @break @case('checkbox') @foreach($question->options as $option)
@@ -201,9 +147,8 @@
@endif - @else -

You have submitted the doctor tagging. Please Edit through View History option if any changes are to be done.

+

You have already submitted 10 Doctors

@endif
@@ -269,18 +214,13 @@ // 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) { - return (a.display || '').localeCompare(b.display || '', undefined, { sensitivity: 'base' }); - }); - + contacts = contacts.filter(function(itm) { return itm.value !== 'sample'; }); console.log(contacts); - + // 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 () { + $("[id^='field-contact_id']").each(function () { var select = $(this); // Avoid re-initializing select2 if (select.data("select2")) return; @@ -292,26 +232,23 @@ }); } - $('input[id^="field-msl_code"], input[id^="field-speciality"]').prop('readonly', true); - - - function enforceUniqueDoctorSelections() { var selectedValues = []; - - $("select[id^='field-contact_id']").each(function () { + // Collect selected values (ignore empty) + $("[id^='field-contact_id']").each(function () { var v = $(this).val(); if (v) selectedValues.push(String(v)); }); - - $("select[id^='field-contact_id']").each(function () { + // Reset all option disabled states, then disable duplicates across selects + $("[id^='field-contact_id']").each(function () { var currentSelect = $(this); var currentVal = currentSelect.val() ? String(currentSelect.val()) : ""; currentSelect.find("option").prop("disabled", false); + // Disable values selected in OTHER selects (keep current selection enabled) selectedValues.forEach(function (v) { if (v && v !== currentVal) { currentSelect @@ -320,54 +257,37 @@ } }); - - if (currentSelect.hasClass("select2-hidden-accessible")) { - - currentSelect.select2({ - width: "100%", - placeholder: "-- Select --", - allowClear: true - }); + // Refresh select2 UI if present + if (currentSelect.data("select2")) { + currentSelect.trigger("change.select2"); } }); - } + } - - $("select[id^='field-contact_id']").each(function() { - var select = $(this); - // Clear previous options - - var savedValue = select.attr('data-selected') || select.data('selected') || select.val() || ''; - select.empty(); - - // 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); - - - - // 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); - } - - select.append(option); - }); + $("[id^='field-contact_id']").each(function() { + var select = $(this); + // Clear previous options + select.html(''); + // 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); + // 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); + } + select.append(option); + }); // For each select element, add a change event handler to populate `msl_code` and `speciality` // We assume dropdowns and targets follow the pattern: @@ -375,49 +295,153 @@ // - result: field-msl_code_1, field-speciality_1, etc. // 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] : ''; + 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] : ''; - // Build the target msl_code and speciality field ids - var mslCodeField = $('#field-msl_code' + suffix); - var specialityField = $('#field-speciality' + suffix); + // Build the target msl_code and speciality field ids + var mslCodeField = $('#field-msl_code' + suffix); + var specialityField = $('#field-speciality' + suffix); - if (mslCodeField.length) { - mslCodeField.val(selected.attr('msl_code') || ''); - } - if (specialityField.length) { - specialityField.val(selected.attr('speciality') || ''); - } - - // Prevent selecting the same doctor across multiple dropdowns - enforceUniqueDoctorSelections(); - }); - - if (savedValue) { - select.val(savedValue).trigger('change'); + if (mslCodeField.length) { + mslCodeField.val(selected.attr('msl_code') || ''); + } + if (specialityField.length) { + specialityField.val(selected.attr('speciality') || ''); } - - }); - - // Ensure unique selection is enforced after initial render + // Prevent selecting the same doctor across multiple dropdowns enforceUniqueDoctorSelections(); - // Enable search on doctor dropdowns - applySelect2ToDoctorDropdowns(); - $("#pageloader").fadeOut(); + }); + + // Ensure unique selection is enforced after initial render + enforceUniqueDoctorSelections(); }); - - - + + // Enable search on doctor dropdowns + applySelect2ToDoctorDropdowns(); + $("#pageloader").fadeOut(); + }); @endif + for (let i = 1; i <= 10; i++) { + $(`#field-mobile_number_${i}`).on('input', function () { + + // Remove non-numeric characters + this.value = this.value.replace(/\D/g, ''); + + // Limit to 10 digits + if (this.value.length > 10) { + this.value = this.value.slice(0, 10); + } + }); + } + + for (let i = 1; i <= 10; i++) { + + $(`#field-email_id_${i}`).on('input', function () { + + // Remove spaces + this.value = this.value.replace(/\s/g, ''); + }); + + $(`#field-email_id_${i}`).on('blur', function () { + + let email = $(this).val().trim(); + + let emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; + + if (email !== '' && !emailPattern.test(email)) { + alert('Please enter a valid email address'); + $(this).focus(); + } + }); + + } + + // Loop through hierarcies and fetch contacts for each hierarchy, store in contacts variable + // $('#field-user_id').change(function(){ + // let hierarchy = $('option:selected', this).attr('hierarchy'); + // $('#field-hierarchy_id').val(hierarchy) + // event.preventDefault(); + // $("#pageloader").fadeIn(); + // $.ajax({ + // type: "GET", + // url: '/form/getdoctorlist?partition={{$form->partition}}&hierarchy='+hierarchy, + // processData: false, + // contentType: false, + // success: function( data ) { + // $("#pageloader").fadeOut(); + // for (let i = 1; i <= 10; i++) { + + // let contactField = $('#field-contact_id_' + i); + + // // Skip if field does not exist + // if (!contactField.length) continue; + + // contactField.html(''); + // contactField.append( + // $("") + // .attr("value", '') + // .text('-- Select --') + // ); + + // for (let itm of data) { + // contactField.append( + // $("") + // .attr("value", itm.value) + // .text(itm.display) + // .attr("msl_code", itm.contact.msl_code) + // .attr("speciality", itm.contact.speciality) + + // ); + // } + + + + // // Remove old change events before binding again + + + // contactField.off('change').on('change', function () { + + // let selected = $(this).find(':selected'); + + // $('#field-msl_code_' + i).val(selected.attr('msl_code') || ''); + + // $('#field-speciality_' + i).val(selected.attr('speciality') || ''); + + // console.log(selected.text()); // selected doctor name + // }); + + // contactField.select2({ + // placeholder: "-- Select --", + // allowClear: true, + // width: '100%' + // }); + + + + // } + + + + + // }, + // }); + + // console.log(hierarchy) + // }) + + // for (let i = 1; i <= 10; i++) { + // $('#field-msl_code_' + i).attr('readonly',true); + // $('#field-speciality_' + i).attr('readonly',true); + // } $('#report-form').on('submit', function(event){ event.preventDefault(); @@ -463,8 +487,7 @@ var plandateField = document.getElementById('field-record_date'); - - + plandateField.setAttribute('max', today); });