Molecule Identification Form Changes Doctor Duplication avoid in submited form and Edit form
Specific Folder FTP Upload / ftp-deploy (push) Successful in 39s Details

This commit is contained in:
Farhan Pathan 2026-06-11 15:19:00 +05:30
parent 9001087b18
commit 0e5fc40615
1 changed files with 158 additions and 14 deletions

View File

@ -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
});