Team 4 (Mother Forum)
Specific Folder FTP Upload / ftp-deploy (push) Successful in 36s Details

This commit is contained in:
zeeshan 2026-10-09 17:43:37 +05:30
parent 5302263349
commit dee26ee664
1 changed files with 59 additions and 65 deletions

View File

@ -77,7 +77,7 @@
<textarea id="field-{{$question->code}}" name="{{$question->code}}" class="form-control" {{$question->required == 'yes'?'required':'' }}>{{isset($question->value)?$question->value:''}}</textarea> <textarea id="field-{{$question->code}}" name="{{$question->code}}" class="form-control" {{$question->required == 'yes'?'required':'' }}>{{isset($question->value)?$question->value:''}}</textarea>
@break @break
@case('dropdown') @case('dropdown')
<select class="form-control" id="field-{{ $question->code }}" name="{{ $question->code }}" {{ $question->required == 'yes' ? 'required' : '' }}> <select class="form-control" id="field-{{ $question->code }}" name="{{ $question->code }}" data-initial-value="{{ isset($question->value) ? $question->value : '' }}" {{ $question->required == 'yes' ? 'required' : '' }}>
<option value=""> -- Select -- </option> <option value=""> -- Select -- </option>
@foreach ($question->options as $option) @foreach ($question->options as $option)
@if($question->code == 'contact_id' && isset($option->contact->type) && $option->contact->type == 'doctor' ) @if($question->code == 'contact_id' && isset($option->contact->type) && $option->contact->type == 'doctor' )
@ -220,7 +220,6 @@
function applySelect2ToDoctorDropdowns() { function applySelect2ToDoctorDropdowns() {
$("[id^='field-contact_id']").each(function () { $("[id^='field-contact_id']").each(function () {
var select = $(this); var select = $(this);
// Avoid re-initializing select2
if (select.data("select2")) return; if (select.data("select2")) return;
select.select2({ select.select2({
width: "100%", width: "100%",
@ -246,7 +245,6 @@
currentSelect.find("option").prop("disabled", false); currentSelect.find("option").prop("disabled", false);
// Disable values selected in OTHER selects (keep current selection enabled)
selectedValues.forEach(function (v) { selectedValues.forEach(function (v) {
if (v && v !== currentVal) { if (v && v !== currentVal) {
currentSelect currentSelect
@ -255,84 +253,80 @@
} }
}); });
// Refresh select2 UI if present
if (currentSelect.data("select2")) { if (currentSelect.data("select2")) {
currentSelect.trigger("change.select2"); currentSelect.trigger("change.select2");
} }
}); });
} }
$("[id^='field-contact_id']").each(function() { $("[id^='field-contact_id']").each(function() {
var select = $(this); var select = $(this);
// Clear previous options
var existingVal = select.val();
select.html('');
// Add a default 'Select' option
select.append(
$("<option></option>")
.attr("value", '')
.text('-- Select --')
);
// Append options from contacts
contacts.forEach(function(itm) {
var option = $("<option></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: var existingVal = select.attr('data-initial-value') || select.val();
// - select: field-contact_id_1, field-contact_id_2, ..., field-contact_id
// - result: field-msl_code_1, field-speciality_1, etc.
// Remove any old event handlers first to prevent duplicate bindings
select.empty();
if (existingVal) { // Default option
select.val(existingVal); select.append($("<option></option>").attr("value", '').text('-- Select --'));
}
select.off('change').on('change', function () {
var selected = $(this).find(':selected'); contacts.forEach(function(itm) {
var option = $("<option></option>")
var selectId = $(this).attr('id'); // e.g., field-contact_id_1 .attr("value", itm.value)
// Extract the suffix (e.g., _1 or empty) .text(itm.display);
var match = selectId.match(/^field-contact_id(_\d+)?$/);
var suffix = match && match[1] ? match[1] : '';
// Build the target msl_code and speciality field ids if (itm.contact && itm.contact.msl_code) {
var mslCodeField = $('#field-msl_code' + suffix); option.attr("msl_code", itm.contact.msl_code);
var specialityField = $('#field-speciality' + suffix); }
if (itm.contact && itm.contact.speciality) {
option.attr("speciality", itm.contact.speciality);
}
select.append(option);
});
if (mslCodeField.length) {
mslCodeField.val(selected.attr('msl_code') || ''); if (existingVal) {
} select.val(String(existingVal));
if (specialityField.length) { }
specialityField.val(selected.attr('speciality') || '');
}
// Prevent selecting the same doctor across multiple dropdowns
enforceUniqueDoctorSelections(); 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] : '';
if (existingVal) { var mslCodeField = $('#field-msl_code' + suffix);
select.trigger('change'); var specialityField = $('#field-speciality' + suffix);
}
// Ensure unique selection is enforced after initial render if (mslCodeField.length) {
enforceUniqueDoctorSelections(); mslCodeField.val(selected.attr('msl_code') || '');
}); }
if (specialityField.length) {
specialityField.val(selected.attr('speciality') || '');
}
// Enable search on doctor dropdowns enforceUniqueDoctorSelections();
applySelect2ToDoctorDropdowns(); });
$("#pageloader").fadeOut(); });
applySelect2ToDoctorDropdowns();
$("[id^='field-contact_id']").each(function() {
var select = $(this);
var existingVal = select.attr('data-initial-value');
if (existingVal) {
select.val(String(existingVal)).trigger('change');
}
});
$("#pageloader").fadeOut();
}); });