771 lines
33 KiB
PHP
771 lines
33 KiB
PHP
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
@include('layouts.shared/title-meta', ['title' => 'Form'])
|
|
@include('layouts.shared/head-css', ['mode' => $mode ?? '', 'demo' => $demo ?? ''])
|
|
<link href="{{ asset('assets/libs/sweetalert2/sweetalert2.min.css') }}" rel="stylesheet" type="text/css" />
|
|
</head>
|
|
<div id="pageloader">
|
|
<img src="http://cdnjs.cloudflare.com/ajax/libs/semantic-ui/0.16.1/images/loader-large.gif" alt="processing..." />
|
|
</div>
|
|
|
|
<body class="loading">
|
|
<div class="account-pages">
|
|
<div class="container">
|
|
<div class="row justify-content-center">
|
|
<div class="col-md-8 col-lg-6 col-xl-5 p-0">
|
|
<div class="card bg-pattern">
|
|
<div class="card-body p-3 row">
|
|
|
|
@if (Session::has('error'))
|
|
<div class="alert alert-danger">{{ Session::get('error') }}</div>
|
|
<br>
|
|
@endif
|
|
@if (session('success'))
|
|
<div class=" alert alert-success">{{ session('success') }}
|
|
</div>
|
|
<br>
|
|
@endif
|
|
<div class="col-8">
|
|
<h4 class="page-title">{{ $form->title }}</h4>
|
|
</div>
|
|
@if (!isset($form->is_approval) || (isset($form->is_approval) && $form->is_approval != 'yes'))
|
|
<div class="col-4">
|
|
@if ($form->link_type == 'form')
|
|
<a href="/form/history" class="float-end pt-1">View History</a>
|
|
@else
|
|
<a href="{{ url()->previous() }}" class="float-end pt-1">Back</a>
|
|
@endif
|
|
</div>
|
|
@endif
|
|
|
|
@php
|
|
$history = Formhelper::getMultiformData(
|
|
$form->partition,
|
|
$form->form_id,
|
|
$form->user_id,
|
|
);
|
|
$submissions = $history->data->submissions ?? [];
|
|
// echo "<pre>";
|
|
// print_r($submissions);
|
|
@endphp
|
|
<form method="POST" action="/form/submit" id="report-form" enctype="multipart/form-data">
|
|
<input type="hidden" name="form_id" value="{{ $form_id }}">
|
|
<input type="hidden" name="user_id" value="{{ $form->user_id }}">
|
|
|
|
@csrf
|
|
@if ($id)
|
|
<input type="hidden" name="id" value="{{ $id }}">
|
|
@endif
|
|
@if (isset($form->manager_can_submit) && $form->manager_can_submit == true)
|
|
<div class="col-md-12 mb-2">
|
|
<label for="field-user_id" class="form-label"> Select User / Territory <span
|
|
class="text-danger">*</span> </label>
|
|
<select class="form-control" id="field-user_id" name="user_id" required>
|
|
<option value=""> -- Select -- </option>
|
|
@foreach ($form->users as $option)
|
|
<option value="{{ $option->value }}"
|
|
hierarchy="{{ $option->hierarchy_id }}"
|
|
{{ isset($question->value) && $question->value == $option->value ? 'selected' : '' }}>
|
|
{{ $option->display }}</option>
|
|
@endforeach
|
|
</select>
|
|
<input type="hidden" id="field-hierarchy_id" name="hierarchy_id"
|
|
value="">
|
|
</div>
|
|
@endif
|
|
|
|
@foreach ($questions as $question)
|
|
<div class="col-md-12 mb-2">
|
|
@if ($question->code == 'category')
|
|
@else
|
|
<label for="field-{{ $question->code }}"
|
|
class="form-label">{{ $question->question }} {!! $question->required == 'yes' ? '<span class="text-danger">*</span>' : '' !!}
|
|
</label>
|
|
@endif
|
|
@switch($question->type)
|
|
@case('hidden')
|
|
<input type="{{ $question->type }}" id="field-{{ $question->code }}"
|
|
name="{{ $question->code }}"
|
|
value="{{ isset($question->value) ? $question->value : '' }}">
|
|
@break
|
|
|
|
@case('text')
|
|
@case('email')
|
|
|
|
@case('tel')
|
|
@case('date')
|
|
<input type="{{ $question->type }}" id="field-{{ $question->code }}"
|
|
name="{{ $question->code }}" class="form-control"
|
|
{{ $question->required == 'yes' ? 'required' : '' }}
|
|
value="{{ isset($question->value) ? $question->value : '' }}">
|
|
@break
|
|
|
|
@case('number')
|
|
<input type="{{ $question->type }}" min="0" max="9999999999"
|
|
step="1" id="field-{{ $question->code }}"
|
|
name="{{ $question->code }}" class="form-control"
|
|
{{ $question->required == 'yes' ? 'required' : '' }}
|
|
value="{{ isset($question->value) ? $question->value : 0 }}">
|
|
@break
|
|
|
|
@case('textarea')
|
|
<textarea id="field-{{ $question->code }}" name="{{ $question->code }}" class="form-control"
|
|
{{ $question->required == 'yes' ? 'required' : '' }}>{{ isset($question->value) ? $question->value : '' }}</textarea>
|
|
@break
|
|
|
|
@case('dropdown')
|
|
@if ($question->code == 'category')
|
|
<div class="category"
|
|
style="border: 1.5px solid #007bff; border-radius: 8px; padding: 10px 14px;">
|
|
<label for="field-{{ $question->code }}"
|
|
class="form-label">{{ $question->question }}
|
|
{!! $question->required == 'yes' ? '<span class="text-danger">*</span>' : '' !!} </label>
|
|
<select class="form-control" id="field-{{ $question->code }}"
|
|
name="{{ $question->code }}"
|
|
{{ $question->required == 'yes' ? 'required' : '' }}>
|
|
<option value=""> -- Select -- </option>
|
|
@foreach ($question->options as $option)
|
|
<option value="{{ $option->value }}"
|
|
{{ isset($question->value) && $question->value == $option->value ? 'selected' : '' }}>
|
|
{{ $option->display }}</option>
|
|
@endforeach
|
|
</select>
|
|
</div>
|
|
@elseif(preg_match('/^doctor_(?:[1-9]|1[0-9]|20)$/', $question->code))
|
|
<select class="form-control" id="field-{{ $question->code }}"
|
|
name="{{ $question->code }}"
|
|
{{ $question->required == 'yes' ? 'required' : '' }}>
|
|
<option value=""> -- Select -- </option>
|
|
@foreach ($question->options as $option)
|
|
@if (isset($option->contact->type) && $option->contact->type != 'chemist')
|
|
<option value="{{ $option->value }}"
|
|
po5_synchrobreathe_non_prescriber="{{ isset($option->contact->po5_synchrobreathe_non_prescriber) ? $option->contact->po5_synchrobreathe_non_prescriber : '' }}"
|
|
po5_ciphaler_non_prescriber="{{ isset($option->contact->po5_ciphaler_non_prescriber) ? $option->contact->po5_ciphaler_non_prescriber : '' }}"
|
|
{{ isset($question->value) && $question->value == $option->value ? 'selected' : '' }}>
|
|
{{ $option->display }}
|
|
</option>
|
|
@endif
|
|
@endforeach
|
|
</select>
|
|
@else
|
|
<select class="form-control" id="field-{{ $question->code }}"
|
|
name="{{ $question->code }}"
|
|
{{ $question->required == 'yes' ? 'required' : '' }}>
|
|
<option value=""> -- Select -- </option>
|
|
@foreach ($question->options as $option)
|
|
<option value="{{ $option->value }}"
|
|
{{ isset($question->value) && $question->value == $option->value ? 'selected' : '' }}>
|
|
{{ $option->display }}</option>
|
|
@endforeach
|
|
</select>
|
|
@endif
|
|
@break
|
|
|
|
@case('checkbox')
|
|
@foreach ($question->options as $option)
|
|
<div class="form-check mb-2 form-check-primary">
|
|
<input class="form-check-input" type="checkbox"
|
|
id="field-{{ $question->code }}-{{ $option->value }}"
|
|
name="{{ $question->code }}[]" value="{{ $option->value }}"
|
|
{{ isset($question->value) && $question->value != '' && in_array($option->value, $question->value) ? 'checked' : '' }}>
|
|
<label class="form-check-label"
|
|
for="field-{{ $question->code }}-{{ $option->value }}">{{ $option->display }}</label>
|
|
</div>
|
|
@endforeach
|
|
@break
|
|
|
|
@case('file')
|
|
<input type="file" id="field-{{ $question->code }}"
|
|
name="{{ $question->code }}" class="form-control" value=""
|
|
accept="image/jpg, image/jpeg, image/png"
|
|
{{ $question->required == 'yes' ? 'required' : '' }}>
|
|
@break
|
|
|
|
@case('multitextbox')
|
|
<div class="row">
|
|
@foreach ($question->options as $option)
|
|
<div class="col-6">{{ $option->display }}</div>
|
|
<div class="col-6 mb-1">
|
|
<input type="number" id="field-{{ $option->value }}"
|
|
name="{{ $option->value }}" class="form-control" required
|
|
value="{{ isset($option->val) ? $option->val : 0 }}">
|
|
</div>
|
|
@endforeach
|
|
</div>
|
|
@break
|
|
@endswitch
|
|
</div>
|
|
@endforeach
|
|
@if (!isset($form->is_approval) || (isset($form->is_approval) && $form->is_approval != 'yes'))
|
|
<div class="text-center d-grid mt-3">
|
|
<button class="btn btn-primary" type="submit" id="submit-btn"> Submit
|
|
</button>
|
|
</div>
|
|
@endif
|
|
</form>
|
|
|
|
</div> <!-- end card-body -->
|
|
</div>
|
|
<!-- end card -->
|
|
|
|
<!-- end row -->
|
|
|
|
</div> <!-- end col -->
|
|
</div>
|
|
<!-- end row -->
|
|
</div>
|
|
<!-- end container -->
|
|
</div>
|
|
<!-- end page -->
|
|
<style type="text/css">
|
|
#pageloader {
|
|
background: rgba(255, 255, 255, 0.8);
|
|
display: none;
|
|
height: 100%;
|
|
position: fixed;
|
|
width: 100%;
|
|
z-index: 9999;
|
|
}
|
|
|
|
#pageloader img {
|
|
left: 50%;
|
|
margin-left: -32px;
|
|
margin-top: -32px;
|
|
position: absolute;
|
|
top: 50%;
|
|
}
|
|
</style>
|
|
@include('layouts.shared/footer-script')
|
|
<script src="{{ asset('assets/libs/sweetalert2/sweetalert2.min.js') }}"></script>
|
|
<script type="text/javascript">
|
|
jQuery(document).ready(function($) {
|
|
|
|
|
|
|
|
|
|
$('#field-user_id').change(function() {
|
|
let hierarchy = $('option:selected', this).attr('hierarchy');
|
|
$('#field-hierarchy_id').val(hierarchy)
|
|
event.preventDefault();
|
|
$.ajax({
|
|
type: "GET",
|
|
url: '/form/getdoctorlist?partition={{ $form->partition }}&hierarchy=' +
|
|
hierarchy,
|
|
processData: false,
|
|
contentType: false,
|
|
success: function(data) {
|
|
$("#pageloader").fadeOut();
|
|
$('#field-contact_id').html('')
|
|
$('#field-contact_id').append($("<option></option>").attr("value", '')
|
|
.text('-- Select --'));
|
|
for (let itm of data) {
|
|
$('#field-contact_id').append($("<option></option>").attr("value",
|
|
itm.value).text(itm.display));
|
|
}
|
|
},
|
|
});
|
|
|
|
console.log(hierarchy)
|
|
})
|
|
|
|
$('#report-form').on('submit', function(event) {
|
|
event.preventDefault();
|
|
$("#pageloader").fadeIn();
|
|
$.ajax({
|
|
type: "POST",
|
|
url: '/form/ajaxsubmitmultiple',
|
|
data: new FormData($('#report-form')[0]),
|
|
processData: false,
|
|
contentType: false,
|
|
success: function(data) {
|
|
$("#pageloader").fadeOut();
|
|
if (data.status == 'success') {
|
|
Swal.fire({
|
|
title: 'Great!',
|
|
text: 'Your data is successfully submitted!',
|
|
icon: 'success'
|
|
}).then(() => {
|
|
location.reload();
|
|
});
|
|
} else {
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Data not submitted',
|
|
text: 'Something went wrong, please try again after some time!'
|
|
})
|
|
}
|
|
|
|
},
|
|
});
|
|
});
|
|
});
|
|
</script>
|
|
|
|
@if (!empty($submissions))
|
|
<script>
|
|
$(document).ready(function() {
|
|
|
|
console.log("is not empty")
|
|
|
|
// ==============================
|
|
// 📦 Compact log collector
|
|
// ==============================
|
|
let logs = [];
|
|
|
|
function log(msg, data = null) {
|
|
if (data) {
|
|
logs.push(msg + ' ' + JSON.stringify(data).substring(0, 100));
|
|
} else {
|
|
logs.push(msg);
|
|
}
|
|
}
|
|
|
|
function showLogs() {
|
|
console.log('🧾 FINAL LOGS:\n' + logs.join('\n'));
|
|
}
|
|
|
|
// ==============================
|
|
// 🎯 Helper
|
|
// ==============================
|
|
function short(val) {
|
|
if (!val) return val;
|
|
return val.toString().substring(0, 8) + '...';
|
|
}
|
|
|
|
const doctorSelects = $(
|
|
'#field-doctor_1, #field-doctor_2, #field-doctor_3, #field-doctor_4, #field-doctor_5, #field-doctor_6, #field-doctor_7, #field-doctor_8, #field-doctor_9, #field-doctor_10, #field-doctor_11, #field-doctor_12, #field-doctor_13, #field-doctor_14, #field-doctor_15, #field-doctor_16, #field-doctor_17, #field-doctor_18, #field-doctor_19, #field-doctor_20'
|
|
);
|
|
|
|
const submissionData = @json($submissions);
|
|
|
|
let currentCategory = $('#field-category').val() || '';
|
|
|
|
log('Script Loaded');
|
|
log('Initial Category', currentCategory);
|
|
|
|
// ==============================
|
|
// 🌍 Get saved (DB) doctor IDs
|
|
// ==============================
|
|
function getGloballyUsedDoctorIds(excludeCategory = null) {
|
|
|
|
let usedIds = [];
|
|
|
|
Object.values(submissionData).forEach(item => {
|
|
|
|
if (
|
|
item.formdata &&
|
|
item.formdata.category !== excludeCategory
|
|
) {
|
|
if (item.contacts && item.contacts.length) {
|
|
item.contacts.forEach(contact => {
|
|
if (contact && contact.id) {
|
|
usedIds.push(contact.id);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
});
|
|
|
|
return [...new Set(usedIds)];
|
|
}
|
|
|
|
// ==============================
|
|
// ⚡ Get LIVE selected doctor IDs
|
|
// ==============================
|
|
function getCurrentlySelectedDoctorIds() {
|
|
|
|
let ids = [];
|
|
|
|
$('[id^="field-doctor_"]').each(function() {
|
|
let val = $(this).val();
|
|
if (val) ids.push(val);
|
|
});
|
|
|
|
return ids;
|
|
}
|
|
|
|
// ==============================
|
|
// 🔁 Prevent duplicates + UX styling
|
|
// ==============================
|
|
function refreshDoctorOptions() {
|
|
|
|
if (!currentCategory) return;
|
|
|
|
const selected = doctorSelects.map(function() {
|
|
return $(this).val();
|
|
}).get().filter(v => v);
|
|
|
|
const dbUsed = getGloballyUsedDoctorIds(currentCategory);
|
|
const liveUsed = getCurrentlySelectedDoctorIds();
|
|
|
|
const finalUsed = [...new Set([...dbUsed, ...liveUsed])];
|
|
|
|
log('Selected doctors', selected.map(short));
|
|
log('DB used doctors', dbUsed.map(short));
|
|
log('Live used doctors', liveUsed.map(short));
|
|
|
|
doctorSelects.each(function() {
|
|
|
|
const $select = $(this);
|
|
const current = $select.val();
|
|
|
|
// 🔄 Reset
|
|
$select.find('option').prop('disabled', false).css({
|
|
'color': '',
|
|
'background-color': ''
|
|
});
|
|
|
|
// 🧼 Clean labels
|
|
$select.find('option').each(function() {
|
|
let txt = $(this).text()
|
|
.replace(' (Selected)', '')
|
|
.replace(' (Already Tagged)', '')
|
|
.replace(' (In Use)', '');
|
|
$(this).text(txt);
|
|
});
|
|
|
|
// ❌ Same form duplicate
|
|
selected.forEach(id => {
|
|
if (id && id !== current) {
|
|
|
|
const $opt = $select.find(`option[value="${id}"]`);
|
|
|
|
$opt.prop('disabled', true)
|
|
.css({
|
|
'color': '#999',
|
|
'background-color': '#f5f5f5'
|
|
});
|
|
|
|
if (!$opt.text().includes('(Selected)')) {
|
|
$opt.text($opt.text() + ' (Selected)');
|
|
}
|
|
}
|
|
});
|
|
|
|
// 🚫 Global restriction (DB + LIVE)
|
|
finalUsed.forEach(id => {
|
|
if (id && id !== current) {
|
|
|
|
const $opt = $select.find(`option[value="${id}"]`);
|
|
|
|
$opt.prop('disabled', true)
|
|
.css({
|
|
'color': '#bbb',
|
|
'background-color': '#f2f2f2'
|
|
});
|
|
|
|
if (!$opt.text().includes('(In Use)')) {
|
|
$opt.text($opt.text() + ' (In Use)');
|
|
}
|
|
}
|
|
});
|
|
|
|
});
|
|
}
|
|
|
|
// ==============================
|
|
// 🔍 STRICT FILTER (KEY FIX)
|
|
// ==============================
|
|
function filterDoctorsByCategory(category) {
|
|
|
|
if (!category) return;
|
|
|
|
doctorSelects.each(function () {
|
|
|
|
const $select = $(this);
|
|
const current = $select.val();
|
|
|
|
let isCurrentValid = true;
|
|
|
|
$select.find('option').each(function () {
|
|
|
|
let val = $(this).val();
|
|
if (!val) return;
|
|
|
|
let sb = ($(this).attr('po5_synchrobreathe_non_prescriber') || '').trim();
|
|
let cip = ($(this).attr('po5_ciphaler_non_prescriber') || '').trim();
|
|
|
|
let isValid = true;
|
|
|
|
if (category === 'SB Dr Tagging') {
|
|
isValid = (sb === 'Yes');
|
|
}
|
|
|
|
if (category === 'Ciphaler Dr Tagging') {
|
|
isValid = (cip === 'Yes');
|
|
}
|
|
|
|
if (!isValid) {
|
|
$(this).hide(); // ❌ hide invalid
|
|
if (val === current) {
|
|
isCurrentValid = false;
|
|
}
|
|
} else {
|
|
$(this).show(); // ✅ valid
|
|
}
|
|
|
|
});
|
|
|
|
// ❌ remove invalid selected
|
|
if (!isCurrentValid) {
|
|
$select.val('');
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
// ==============================
|
|
// ⏳ Wait until options are loaded
|
|
// ==============================
|
|
function waitForOptionsAndSet($select, value, attempt = 0) {
|
|
|
|
if ($select.find(`option[value="${value}"]`).length) {
|
|
$select.val(value).trigger('change');
|
|
log(`✅ Set ${$select.attr('id')}`, short(value));
|
|
}
|
|
else if (attempt < 15) {
|
|
setTimeout(() => {
|
|
waitForOptionsAndSet($select, value, attempt + 1);
|
|
}, 200);
|
|
}
|
|
else {
|
|
log(`❌ Option not found`, {
|
|
field: $select.attr('id'),
|
|
value: short(value)
|
|
});
|
|
}
|
|
}
|
|
|
|
// ==============================
|
|
// 📂 Populate
|
|
// ==============================
|
|
function populateDoctorsByCategory(category) {
|
|
|
|
currentCategory = category;
|
|
|
|
if (!category) return;
|
|
|
|
const match = Object.values(submissionData)
|
|
.sort((a, b) => new Date(b.createdAt) - new Date(a.createdAt))
|
|
.find(item => item.formdata && item.formdata.category === category);
|
|
|
|
log('Matched submission found', !!match);
|
|
|
|
// 🔄 reset
|
|
doctorSelects.val('');
|
|
$('[id^="field-breathefree_is_available_"]').val('');
|
|
|
|
if (match && match.contacts && match.contacts.length) {
|
|
|
|
match.contacts.forEach((contact, index) => {
|
|
|
|
const i = index + 1;
|
|
|
|
const $doctorSelect = $(`#field-doctor_${i}`);
|
|
const $availabilitySelect = $(`#field-breathefree_is_available_${i}`);
|
|
|
|
if (contact && contact.id) {
|
|
log(`Mapping doctor_${i}`, {
|
|
id: short(contact.id),
|
|
name: contact.name
|
|
});
|
|
|
|
waitForOptionsAndSet($doctorSelect, contact.id);
|
|
}
|
|
|
|
const availabilityValue = match.formdata[`breathefree_is_available_${i}`];
|
|
|
|
if (availabilityValue) {
|
|
$availabilitySelect.val(availabilityValue).trigger('change');
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
setTimeout(() => {
|
|
filterDoctorsByCategory(category); // ✅ KEY
|
|
refreshDoctorOptions();
|
|
showLogs();
|
|
}, 1200);
|
|
}
|
|
|
|
// ==============================
|
|
// 🔁 Events
|
|
// ==============================
|
|
$('#field-category').on('change', function() {
|
|
|
|
let category = $(this).val();
|
|
|
|
setTimeout(() => {
|
|
populateDoctorsByCategory(category);
|
|
filterDoctorsByCategory(category); // ✅ KEY
|
|
}, 300);
|
|
|
|
});
|
|
|
|
if (currentCategory) {
|
|
setTimeout(() => {
|
|
populateDoctorsByCategory(currentCategory);
|
|
}, 300);
|
|
}
|
|
|
|
doctorSelects.on('change', function() {
|
|
refreshDoctorOptions();
|
|
});
|
|
|
|
});
|
|
</script>
|
|
@endif
|
|
|
|
@if (empty($submissions))
|
|
<script>
|
|
$(document).ready(function() {
|
|
|
|
console.log("EMPTY MODE SCRIPT LOADED");
|
|
|
|
// ==============================
|
|
// 📦 Store original options
|
|
// ==============================
|
|
let doctorOptions = {};
|
|
|
|
$('[id^="field-doctor_"]').each(function() {
|
|
let id = $(this).attr('id');
|
|
doctorOptions[id] = $(this).find('option').clone();
|
|
});
|
|
|
|
// ==============================
|
|
// 🎯 Prevent duplicate doctors
|
|
// ==============================
|
|
function preventDuplicateDoctors() {
|
|
|
|
let selectedValues = [];
|
|
|
|
// collect selected values
|
|
$('[id^="field-doctor_"]').each(function() {
|
|
let val = $(this).val();
|
|
if (val) selectedValues.push(val);
|
|
});
|
|
|
|
// apply disable logic
|
|
$('[id^="field-doctor_"]').each(function() {
|
|
|
|
let current = $(this).val();
|
|
|
|
$(this).find('option').each(function() {
|
|
|
|
let val = $(this).val();
|
|
|
|
if (!val) return;
|
|
|
|
if (selectedValues.includes(val) && val !== current) {
|
|
|
|
$(this).prop('disabled', true).css({
|
|
'color': '#999',
|
|
'background-color': '#f5f5f5'
|
|
});
|
|
|
|
// add label
|
|
if (!$(this).text().includes('(Selected)')) {
|
|
$(this).text($(this).text() + ' (Selected)');
|
|
}
|
|
|
|
} else {
|
|
|
|
// reset
|
|
let cleanText = $(this).text().replace(' (Selected)', '');
|
|
$(this).text(cleanText);
|
|
|
|
$(this).prop('disabled', false).css({
|
|
'color': '',
|
|
'background-color': ''
|
|
});
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
}
|
|
|
|
// ==============================
|
|
// 🔍 Filter based on category
|
|
// ==============================
|
|
$('#field-category').on('change', function() {
|
|
|
|
let selectedCategory = ($(this).val() || '').trim();
|
|
|
|
$('[id^="field-doctor_"]').each(function() {
|
|
|
|
let dropdown = $(this);
|
|
let id = dropdown.attr('id');
|
|
|
|
// ✅ Always use fresh clone (prevents mutation bugs)
|
|
let allOptions = doctorOptions[id].clone();
|
|
|
|
let html = '';
|
|
|
|
allOptions.each(function() {
|
|
|
|
let val = $(this).val();
|
|
let text = $(this).text();
|
|
|
|
if (!val) {
|
|
html += `<option value="">${text}</option>`;
|
|
return;
|
|
}
|
|
|
|
let sb = ($(this).attr('po5_synchrobreathe_non_prescriber') || '')
|
|
.trim();
|
|
let cip = ($(this).attr('po5_ciphaler_non_prescriber') || '')
|
|
.trim();
|
|
|
|
let isValid = true;
|
|
|
|
if (selectedCategory === 'SB Dr Tagging') {
|
|
isValid = (sb === 'Yes');
|
|
}
|
|
|
|
if (selectedCategory === 'Ciphaler Dr Tagging') {
|
|
isValid = (cip === 'Yes');
|
|
}
|
|
|
|
if (isValid) {
|
|
html += `<option value="${val}"
|
|
po5_synchrobreathe_non_prescriber="${sb}"
|
|
po5_ciphaler_non_prescriber="${cip}">
|
|
${text.replace('(Selected)', '').replace('(In Use)', '')}
|
|
</option>`;
|
|
}
|
|
|
|
});
|
|
|
|
dropdown.html(html);
|
|
|
|
// reset selection
|
|
dropdown.val('');
|
|
});
|
|
|
|
// apply duplicate prevention after filtering
|
|
preventDuplicateDoctors();
|
|
});
|
|
|
|
// ==============================
|
|
// 🔁 On doctor change
|
|
// ==============================
|
|
$(document).on('change', '[id^="field-doctor_"]', function() {
|
|
preventDuplicateDoctors();
|
|
});
|
|
|
|
});
|
|
</script>
|
|
@endif
|
|
|
|
|
|
</body>
|
|
|
|
</html>
|