MERGE_UAT_PRE/POST_LIVE
This commit is contained in:
commit
974032f903
@ -1,16 +1,16 @@
|
|||||||
<style>
|
<style>
|
||||||
.readonly-select {
|
.readonly-select {
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
background-color: #e0e0e0;
|
background-color: #e0e0e0;
|
||||||
color: #666;
|
color: #666;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
<div class="<?= !isset($ticket_data) ? "card" : "" ?>" style="margin-right: 23px;">
|
<div class="<?= !isset($ticket_data) ? "card" : "" ?>" style="margin-right: 23px;">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<?php if(!isset($ticket_data)){ ?>
|
<?php if (!isset($ticket_data)) { ?>
|
||||||
<!-- Header Section -->
|
<!-- Header Section -->
|
||||||
<div class="row mb-3">
|
<div class="row mb-3">
|
||||||
<div class="col-6 d-flex align-items-center">
|
<div class="col-6 d-flex align-items-center">
|
||||||
@ -26,21 +26,21 @@
|
|||||||
<form role="form" class="parsley-examples" method="post" id="ticket_form_data" onsubmit="submitClaimForm(event, this)"
|
<form role="form" class="parsley-examples" method="post" id="ticket_form_data" onsubmit="submitClaimForm(event, this)"
|
||||||
enctype="multipart/form-data">
|
enctype="multipart/form-data">
|
||||||
|
|
||||||
<input type="hidden" id="ticket_master_id" name="ticket_master_id" value="<?= isset($ticket_data['id']) ? $ticket_data['id'] : '' ?>">
|
<input type="hidden" id="ticket_master_id" name="ticket_master_id" value="<?= isset($ticket_data['id']) ? $ticket_data['id'] : '' ?>">
|
||||||
<input type="hidden" id="is_head_approved" name="is_head_approved" value="<?= isset($ticket_data['is_head_approved']) ? $ticket_data['is_head_approved'] : '' ?>">
|
<input type="hidden" id="is_head_approved" name="is_head_approved" value="<?= isset($ticket_data['is_head_approved']) ? $ticket_data['is_head_approved'] : '' ?>">
|
||||||
<input type="hidden" id="extra_fields_array_for_validate" name="extra_fields_array_for_validate" value='<?= isset($extra_fields_array_for_validate) && !empty($extra_fields_array_for_validate) ? json_encode($extra_fields_array_for_validate) : "[]" ?>'>
|
<input type="hidden" id="extra_fields_array_for_validate" name="extra_fields_array_for_validate" value='<?= isset($extra_fields_array_for_validate) && !empty($extra_fields_array_for_validate) ? json_encode($extra_fields_array_for_validate) : "[]" ?>'>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
|
||||||
<h5>Employee Details</h5>
|
<h5>Employee Details</h5>
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
<!-- first_data_points -->
|
<!-- first_data_points -->
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
|
|
||||||
<div class="form-group col-md-3">
|
<div class="form-group col-md-3">
|
||||||
<label for="emp_code">Employee ID <span class="text-danger">*</span> <i class="fa fa-search text-danger"
|
<label for="emp_code">Employee ID <span class="text-danger">*</span> <i class="fa fa-search text-danger"
|
||||||
aria-hidden="true" onclick="openFetchEmpDataodal(this)"></i> <span class="text-danger"></span></label>
|
aria-hidden="true" onclick="openFetchEmpDataodal(this)"></i> <span class="text-danger"></span></label>
|
||||||
<input type="text" class="form-control" id="emp_code" placeholder="Enter Employee ID"
|
<input type="text" class="form-control" id="emp_code" placeholder="Enter Employee ID"
|
||||||
value="<?= isset($ticket_data['emp_code']) ? $ticket_data['emp_code'] : '' ?>"
|
value="<?= isset($ticket_data['emp_code']) ? $ticket_data['emp_code'] : '' ?>"
|
||||||
name="emp_code" required>
|
name="emp_code" required>
|
||||||
@ -92,12 +92,12 @@
|
|||||||
<select class="form-control" id="acm_id" name="acm_id" required>
|
<select class="form-control" id="acm_id" name="acm_id" required>
|
||||||
<!-- <option value="0">Select Account Manager</option> -->
|
<!-- <option value="0">Select Account Manager</option> -->
|
||||||
<?php
|
<?php
|
||||||
if (isset($acms) && count($acms)) {
|
if (isset($acms) && count($acms)) {
|
||||||
foreach ($acms as $key => $value) {
|
foreach ($acms as $key => $value) {
|
||||||
$selected = (isset($ticket_data) && $ticket_data['acm_id'] == $value['id']) ? 'selected' : '';
|
$selected = (isset($ticket_data) && $ticket_data['acm_id'] == $value['id']) ? 'selected' : '';
|
||||||
echo "<option value=" . $value['id'] . " $selected>" . $value['first_name'] . "</option>";
|
echo "<option value=" . $value['id'] . " $selected>" . $value['first_name'] . "</option>";
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
@ -116,14 +116,14 @@
|
|||||||
<label for="ticket_type_id"> Policy Type <span class="text-danger"></span></label>
|
<label for="ticket_type_id"> Policy Type <span class="text-danger"></span></label>
|
||||||
<select class="form-control readonly-select" id="ticket_type_id" name="ticket_type_id" readonly>
|
<select class="form-control readonly-select" id="ticket_type_id" name="ticket_type_id" readonly>
|
||||||
<?php
|
<?php
|
||||||
if (isset($ticket_type) && count($ticket_type)) {
|
if (isset($ticket_type) && count($ticket_type)) {
|
||||||
foreach ($ticket_type as $key => $value) {
|
foreach ($ticket_type as $key => $value) {
|
||||||
if($key != 1){
|
if ($key != 1) {
|
||||||
$selected = (isset($ticket_data) && $ticket_data['ticket_type_id'] == $key) ? 'selected' : ((isset($selected_ticket_type) && $selected_ticket_type == $key) ? 'selected' : '');
|
$selected = (isset($ticket_data) && $ticket_data['ticket_type_id'] == $key) ? 'selected' : ((isset($selected_ticket_type) && $selected_ticket_type == $key) ? 'selected' : '');
|
||||||
echo "<option value='" . $key . "' $selected>" . $value . "</option>";
|
echo "<option value='" . $key . "' $selected>" . $value . "</option>";
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
@ -133,12 +133,12 @@
|
|||||||
<select class="form-control" id="claim_status_id" name="claim_status_id" required>
|
<select class="form-control" id="claim_status_id" name="claim_status_id" required>
|
||||||
<!-- <option value="0">Select status</option> -->
|
<!-- <option value="0">Select status</option> -->
|
||||||
<?php
|
<?php
|
||||||
if (isset($claim_status) && count($claim_status)) {
|
if (isset($claim_status) && count($claim_status)) {
|
||||||
foreach ($claim_status as $key => $value) {
|
foreach ($claim_status as $key => $value) {
|
||||||
$selected = (isset($ticket_data) && $ticket_data['claim_status_id'] == $value['id']) ? 'selected' : '';
|
$selected = (isset($ticket_data) && $ticket_data['claim_status_id'] == $value['id']) ? 'selected' : '';
|
||||||
echo "<option value=" . $value['id'] . " $selected>" . $value['claim_status'] . "</option>";
|
echo "<option value=" . $value['id'] . " $selected>" . $value['claim_status'] . "</option>";
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
@ -148,12 +148,12 @@
|
|||||||
<select class="form-control" id="claim_type" name="claim_type" required>
|
<select class="form-control" id="claim_type" name="claim_type" required>
|
||||||
<!-- <option value="0">Select claim Type</option> -->
|
<!-- <option value="0">Select claim Type</option> -->
|
||||||
<?php
|
<?php
|
||||||
if (isset($claim_type) && count($claim_type)) {
|
if (isset($claim_type) && count($claim_type)) {
|
||||||
foreach ($claim_type as $key => $value) {
|
foreach ($claim_type as $key => $value) {
|
||||||
$selected = (isset($ticket_data) && $ticket_data['claim_type'] == $key) ? 'selected' : '';
|
$selected = (isset($ticket_data) && $ticket_data['claim_type'] == $key) ? 'selected' : '';
|
||||||
echo "<option value='" . $key . "' $selected>" . $value . "</option>";
|
echo "<option value='" . $key . "' $selected>" . $value . "</option>";
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
@ -280,7 +280,7 @@
|
|||||||
<div class="form-group col-md-12 text-right m-b-0" style="margin-top: 29px;">
|
<div class="form-group col-md-12 text-right m-b-0" style="margin-top: 29px;">
|
||||||
<button type="submit" class="btn btn-primary waves-effect waves-light mr-1"
|
<button type="submit" class="btn btn-primary waves-effect waves-light mr-1"
|
||||||
id="btnSubmit">Submit</button>
|
id="btnSubmit">Submit</button>
|
||||||
<?php if(get_role_id() == 5 && isset($ticket_data) && in_array($ticket_data['claim_status_id'],[23,33,43])) { ?>
|
<?php if (get_role_id() == 5 && isset($ticket_data) && in_array($ticket_data['claim_status_id'], [23, 33, 43])) { ?>
|
||||||
<a class="btn btn-secondary waves-effect waves-light mr-1" onclick="showConfirmationModal(event)">Rejected Approve</a>
|
<a class="btn btn-secondary waves-effect waves-light mr-1" onclick="showConfirmationModal(event)">Rejected Approve</a>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
</div>
|
</div>
|
||||||
@ -291,212 +291,259 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
let GlobelExtraFields = [];
|
||||||
|
|
||||||
let GlobelExtraFields = [];
|
$(document).ready(function() {
|
||||||
|
|
||||||
$(document).ready(function() {
|
var date_of_join = flatpickr("#date_of_join", {
|
||||||
|
dateFormat: "d/m/Y",
|
||||||
|
allowInput: false
|
||||||
|
});
|
||||||
|
|
||||||
var date_of_join = flatpickr("#date_of_join", {
|
var dob = flatpickr("#dob", {
|
||||||
dateFormat: "d/m/Y",
|
dateFormat: "d/m/Y",
|
||||||
allowInput: false
|
allowInput: false
|
||||||
});
|
});
|
||||||
|
|
||||||
var dob = flatpickr("#dob", {
|
var date_of_incep = flatpickr("#date_of_incep", {
|
||||||
dateFormat: "d/m/Y",
|
dateFormat: "d/m/Y",
|
||||||
allowInput: false
|
allowInput: false
|
||||||
});
|
});
|
||||||
|
|
||||||
var date_of_incep = flatpickr("#date_of_incep", {
|
var date_of_accident = flatpickr("#date_of_accident", {
|
||||||
dateFormat: "d/m/Y",
|
dateFormat: "d/m/Y",
|
||||||
allowInput: false
|
allowInput: false
|
||||||
});
|
});
|
||||||
|
|
||||||
var date_of_accident = flatpickr("#date_of_accident", {
|
var date_of_death = flatpickr("#date_of_death", {
|
||||||
dateFormat: "d/m/Y",
|
dateFormat: "d/m/Y",
|
||||||
allowInput: false
|
allowInput: false
|
||||||
});
|
});
|
||||||
|
|
||||||
var date_of_death = flatpickr("#date_of_death", {
|
var date_of_intimat = flatpickr("#date_of_intimat", {
|
||||||
dateFormat: "d/m/Y",
|
dateFormat: "d/m/Y",
|
||||||
allowInput: false
|
allowInput: false
|
||||||
});
|
});
|
||||||
|
|
||||||
var date_of_intimat = flatpickr("#date_of_intimat", {
|
flatpickr("#approved_date", {
|
||||||
dateFormat: "d/m/Y",
|
dateFormat: "d/m/Y",
|
||||||
allowInput: false
|
allowInput: false
|
||||||
});
|
});
|
||||||
|
flatpickr("#settled_date", {
|
||||||
|
dateFormat: "d/m/Y",
|
||||||
|
allowInput: false
|
||||||
|
});
|
||||||
|
|
||||||
flatpickr("#approved_date", { dateFormat: "d/m/Y", allowInput: false });
|
// updateClaimStatusDisplay("<?= isset($ticket_data['claim_status_id']) ? $ticket_data['claim_status_id'] : 0 ?>")
|
||||||
flatpickr("#settled_date", { dateFormat: "d/m/Y", allowInput: false });
|
var extraFields = <?= json_encode(isset($extra_fields) ? $extra_fields : []); ?>;
|
||||||
|
GlobelExtraFields = extraFields;
|
||||||
// updateClaimStatusDisplay("<?= isset($ticket_data['claim_status_id']) ? $ticket_data['claim_status_id'] : 0 ?>")
|
console.log("extraFields", extraFields);
|
||||||
var extraFields = <?= json_encode(isset($extra_fields) ? $extra_fields : []); ?>;
|
claimStatusFieldChanges(extraFields);
|
||||||
GlobelExtraFields = extraFields;
|
|
||||||
console.log("extraFields", extraFields);
|
|
||||||
claimStatusFieldChanges(extraFields);
|
|
||||||
|
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
function updateClaimStatusDisplay(value) {
|
function updateClaimStatusDisplay(value) {
|
||||||
|
|
||||||
console.log('value', value);
|
console.log('value', value);
|
||||||
|
|
||||||
// Hide all sections first
|
// Hide all sections first
|
||||||
$('.settled, .approved, .canceled, .returned').hide();
|
$('.settled, .approved, .canceled, .returned').hide();
|
||||||
|
|
||||||
// Show relevant section based on value
|
// Show relevant section based on value
|
||||||
if (value == 20 || value == 30 || value == 40) { // APPROVED
|
if (value == 20 || value == 30 || value == 40) { // APPROVED
|
||||||
$('.approved').show();
|
$('.approved').show();
|
||||||
} else if (value == 24 || value == 34 || value == 44) { // SETTLED
|
} else if (value == 24 || value == 34 || value == 44) { // SETTLED
|
||||||
$('.settled').show();
|
$('.settled').show();
|
||||||
}else if (value == 47 || value == 53 || value == 58) { // CANCELLED
|
} else if (value == 47 || value == 53 || value == 58) { // CANCELLED
|
||||||
$('.canceled').show();
|
$('.canceled').show();
|
||||||
}else if (value == 48 || value == 54 || value == 59) { // RETURNED
|
} else if (value == 48 || value == 54 || value == 59) { // RETURNED
|
||||||
$('.returned').show();
|
$('.returned').show();
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$('#claim_status_id').on('change', function() {
|
|
||||||
updateClaimStatusDisplay($(this).val());
|
|
||||||
});
|
|
||||||
|
|
||||||
function claimStatusFieldChanges(fields) {
|
|
||||||
console.log('fields', fields);
|
|
||||||
fields.forEach(function(fieldId) {
|
|
||||||
var $field = $("#" + fieldId);
|
|
||||||
|
|
||||||
if ($field.length) {
|
|
||||||
// $field.prop('required', true);
|
|
||||||
|
|
||||||
var $parentDiv = $field.closest("div");
|
|
||||||
$parentDiv.show();
|
|
||||||
|
|
||||||
var $label = $parentDiv.find("label[for='" + fieldId + "']");
|
|
||||||
if ($label.length && !$label.find(".text-danger").length) {
|
|
||||||
$label.append(' <span class="text-danger">*</span>');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function claimStatusFieldRemoveREquired(fields, remove_or_add, thirdClass) {
|
|
||||||
|
|
||||||
console.log('--------------------------- claimStatusFieldRemoveREquired ---------------------------');
|
|
||||||
console.log('fields', fields);
|
|
||||||
console.log('remove_or_add', remove_or_add);
|
|
||||||
|
|
||||||
fields.forEach(function(fieldId) {
|
|
||||||
var $field = $("#" + fieldId);
|
|
||||||
|
|
||||||
if ($field.length) {
|
|
||||||
$field.prop('required', remove_or_add);
|
|
||||||
var $parentDiv = $field.closest("div");
|
|
||||||
console.log('parentDiv', $parentDiv);
|
|
||||||
var $label = $parentDiv.find("label[for='" + fieldId + "']");
|
|
||||||
// if(remove_or_add == false){
|
|
||||||
// $parentDiv.find("label[for='" + fieldId + "'] .text-danger").remove();
|
|
||||||
// console.log('one', remove_or_add);
|
|
||||||
// }else{
|
|
||||||
// if ($label.length && !$label.find(".text-danger").length) {
|
|
||||||
// $label.append(' <span class="text-danger">*</span>');
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
$('.'+thirdClass).find('input, textarea').attr('required', true);
|
$('#claim_status_id').on('change', function() {
|
||||||
|
updateClaimStatusDisplay($(this).val());
|
||||||
|
});
|
||||||
|
|
||||||
}
|
function claimStatusFieldChanges(fields) {
|
||||||
|
console.log('fields', fields);
|
||||||
|
fields.forEach(function(fieldId) {
|
||||||
|
var $field = $("#" + fieldId);
|
||||||
|
|
||||||
$(document).on("input", function (event) {
|
if ($field.length) {
|
||||||
|
// $field.prop('required', true);
|
||||||
|
|
||||||
let fields = GlobelExtraFields;
|
var $parentDiv = $field.closest("div");
|
||||||
console.log('fields', fields);
|
$parentDiv.show();
|
||||||
let targetId = event.target.id;
|
|
||||||
console.log('targetId', targetId);
|
|
||||||
console.log('fields.includes(targetId)', fields.includes(targetId));
|
|
||||||
|
|
||||||
if (fields.includes(targetId)) {
|
var $label = $parentDiv.find("label[for='" + fieldId + "']");
|
||||||
|
|
||||||
let $field = $("#" + targetId);
|
|
||||||
console.log('$field id', $field);
|
|
||||||
let $parentDiv = $field.closest("div");
|
|
||||||
console.log('$parentDiv', $parentDiv);
|
|
||||||
// addRequiredFieldSymbol(targetId);
|
|
||||||
if ($parentDiv.length) {
|
|
||||||
let thirdClass = $parentDiv.attr("class").split(" ")[2] || "";
|
|
||||||
addRequiredFieldSymbolByClass(thirdClass);
|
|
||||||
console.log('thirdClass', thirdClass);
|
|
||||||
|
|
||||||
if (thirdClass) {
|
|
||||||
claimStatusFieldRemoveREquired(fields, false, thirdClass);
|
|
||||||
let $label = $(thirdClass).find("label");
|
|
||||||
if ($label.length && !$label.find(".text-danger").length) {
|
if ($label.length && !$label.find(".text-danger").length) {
|
||||||
$label.append(' <span class="text-danger">*</span>');
|
// $label.append(' <span class="text-danger">*</span>');
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
claimStatusFieldRemoveREquired($field, false, '');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// function addRequiredFieldSymbol(field_name) {
|
|
||||||
// // Find the field with the given name
|
|
||||||
// var $field = $(`[name="${field_name}"]`);
|
|
||||||
|
|
||||||
// if ($field.length) {
|
|
||||||
// // Find the parent div of this field
|
|
||||||
// var $parentDiv = $field.closest('div');
|
|
||||||
|
|
||||||
// if ($parentDiv.length) {
|
|
||||||
// // Get the classes as an array
|
|
||||||
// var classes = $parentDiv.attr('class') ? $parentDiv.attr('class').split(/\s+/) : [];
|
|
||||||
|
|
||||||
// if (classes.length > 0) {
|
|
||||||
// // Get the last class in the array
|
|
||||||
// var lastClass = classes[classes.length - 1];
|
|
||||||
|
|
||||||
// // Find all divs with this last class
|
|
||||||
// var $allDivsWithClass = $(`.${lastClass}`);
|
|
||||||
|
|
||||||
// // Add asterisk to all labels within these divs
|
|
||||||
// $allDivsWithClass.each(function() {
|
|
||||||
// var $label = $(this).find('label');
|
|
||||||
// if ($label.length && !$label.find('.text-danger').length) {
|
|
||||||
// $label.append(' <span class="text-danger">*</span>');
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
|
|
||||||
// console.log(`Added required symbol to ${$allDivsWithClass.length} labels with class "${lastClass}"`);
|
|
||||||
// } else {
|
|
||||||
// console.warn(`Parent div for field "${field_name}" has no classes`);
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// console.warn(`No parent div found for field name="${field_name}"`);
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// console.warn(`No field found with name="${field_name}"`);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
function addRequiredFieldSymbolByClass(className) {
|
|
||||||
// Find all divs with the specified class
|
|
||||||
var $divsWithClass = $(`.${className}`);
|
|
||||||
|
|
||||||
if ($divsWithClass.length) {
|
|
||||||
// Add asterisk to all labels within these divs
|
|
||||||
$divsWithClass.each(function() {
|
|
||||||
var $label = $(this).find('label');
|
|
||||||
if ($label.length && !$label.find('.text-danger').length) {
|
|
||||||
$label.append(' <span class="text-danger">*</span>');
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(`Added required symbol to ${$divsWithClass.length} labels with class "${className}"`);
|
|
||||||
} else {
|
|
||||||
console.warn(`No divs found with class="${className}"`);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
function claimStatusFieldRemoveREquired(fields, remove_or_add, thirdClass) {
|
||||||
|
|
||||||
|
console.log('--------------------------- claimStatusFieldRemoveREquired ---------------------------');
|
||||||
|
console.log('fields', fields);
|
||||||
|
console.log('remove_or_add', remove_or_add);
|
||||||
|
|
||||||
|
fields.forEach(function(fieldId) {
|
||||||
|
var $field = $("#" + fieldId);
|
||||||
|
|
||||||
|
if ($field.length) {
|
||||||
|
$field.prop('required', remove_or_add);
|
||||||
|
var $parentDiv = $field.closest("div");
|
||||||
|
console.log('parentDiv', $parentDiv);
|
||||||
|
var $label = $parentDiv.find("label[for='" + fieldId + "']");
|
||||||
|
// if(remove_or_add == false){
|
||||||
|
// $parentDiv.find("label[for='" + fieldId + "'] .text-danger").remove();
|
||||||
|
// console.log('one', remove_or_add);
|
||||||
|
// }else{
|
||||||
|
// if ($label.length && !$label.find(".text-danger").length) {
|
||||||
|
// $label.append(' <span class="text-danger">*</span>');
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// $('.'+thirdClass).find('input, textarea').attr('required', true);
|
||||||
|
let extrafieldsArray = $('#extra_fields_array_for_validate').val();
|
||||||
|
try {
|
||||||
|
extrafieldsArray = JSON.parse(extrafieldsArray); // Convert string to object
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Invalid JSON format in extra_fields_array_for_validate:", error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var selectedClaimStatus = $('#claim_status_id').val();
|
||||||
|
var $thirdClass = $(`.${thirdClass}`);
|
||||||
|
var hasValue = $thirdClass.find('input, textarea, select').filter(function() {
|
||||||
|
return $(this).val().trim() !== ''; // Check if at least one field is not empty
|
||||||
|
}).length > 0;
|
||||||
|
console.log ("has value ",hasValue);
|
||||||
|
$thirdClass.each(function() {
|
||||||
|
var id = $(this).find('[id]').first().attr('id');
|
||||||
|
var $label = $(this).find('label');
|
||||||
|
var $thisDiv = $(this);
|
||||||
|
var $inputs = $thisDiv.find('input, textarea, select');
|
||||||
|
|
||||||
|
|
||||||
|
// ✅ Condition 1: Check if this ID is in extraFieldsArray (required by status)
|
||||||
|
var shouldAddRequired = extrafieldsArray[selectedClaimStatus] && extrafieldsArray[selectedClaimStatus].includes(id);
|
||||||
|
console.log ("shouldAddRequired ",shouldAddRequired);
|
||||||
|
|
||||||
|
// ✅ Condition 2: If any field in the class has a value, make all required
|
||||||
|
if (shouldAddRequired || hasValue) {
|
||||||
|
if ($label.length && !$label.find('.text-danger').length) {
|
||||||
|
$label.append(' <span class="text-danger">*</span>');
|
||||||
|
}
|
||||||
|
// console.log("input from if ", $inputs);
|
||||||
|
// $inputs.attr('required', true);
|
||||||
|
$('.' + thirdClass).find('input, textarea,select').attr('required', true);
|
||||||
|
console.log(`class ${thirdClass} added required label and added required field`);
|
||||||
|
} else {
|
||||||
|
$label.find('.text-danger').remove();
|
||||||
|
console.log("input ", $inputs);
|
||||||
|
// $inputs.prop('required', false);
|
||||||
|
$('.' + thirdClass).find('input, textarea,select').attr('required', false);
|
||||||
|
console.log(`class ${thirdClass} removed required label and removed required field`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$(document).on("input", function(event) {
|
||||||
|
|
||||||
|
let fields = GlobelExtraFields;
|
||||||
|
console.log('fields', fields);
|
||||||
|
let targetId = event.target.id;
|
||||||
|
console.log('targetId', targetId);
|
||||||
|
console.log('fields.includes(targetId)', fields.includes(targetId));
|
||||||
|
|
||||||
|
if (fields.includes(targetId)) {
|
||||||
|
|
||||||
|
let $field = $("#" + targetId);
|
||||||
|
console.log('$field id', $field);
|
||||||
|
let $parentDiv = $field.closest("div");
|
||||||
|
console.log('$parentDiv', $parentDiv);
|
||||||
|
// addRequiredFieldSymbol(targetId);
|
||||||
|
if ($parentDiv.length) {
|
||||||
|
let thirdClass = $parentDiv.attr("class").split(" ")[2] || "";
|
||||||
|
// addRequiredFieldSymbolByClass(thirdClass);
|
||||||
|
console.log('thirdClass', thirdClass);
|
||||||
|
|
||||||
|
if (thirdClass) {
|
||||||
|
claimStatusFieldRemoveREquired(fields, false, thirdClass);
|
||||||
|
let $label = $(thirdClass).find("label");
|
||||||
|
if ($label.length && !$label.find(".text-danger").length) {
|
||||||
|
$label.append(' <span class="text-danger">*</span>');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
claimStatusFieldRemoveREquired($field, false, '');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// function addRequiredFieldSymbol(field_name) {
|
||||||
|
// // Find the field with the given name
|
||||||
|
// var $field = $(`[name="${field_name}"]`);
|
||||||
|
|
||||||
|
// if ($field.length) {
|
||||||
|
// // Find the parent div of this field
|
||||||
|
// var $parentDiv = $field.closest('div');
|
||||||
|
|
||||||
|
// if ($parentDiv.length) {
|
||||||
|
// // Get the classes as an array
|
||||||
|
// var classes = $parentDiv.attr('class') ? $parentDiv.attr('class').split(/\s+/) : [];
|
||||||
|
|
||||||
|
// if (classes.length > 0) {
|
||||||
|
// // Get the last class in the array
|
||||||
|
// var lastClass = classes[classes.length - 1];
|
||||||
|
|
||||||
|
// // Find all divs with this last class
|
||||||
|
// var $allDivsWithClass = $(`.${lastClass}`);
|
||||||
|
|
||||||
|
// // Add asterisk to all labels within these divs
|
||||||
|
// $allDivsWithClass.each(function() {
|
||||||
|
// var $label = $(this).find('label');
|
||||||
|
// if ($label.length && !$label.find('.text-danger').length) {
|
||||||
|
// $label.append(' <span class="text-danger">*</span>');
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
|
||||||
|
// console.log(`Added required symbol to ${$allDivsWithClass.length} labels with class "${lastClass}"`);
|
||||||
|
// } else {
|
||||||
|
// console.warn(`Parent div for field "${field_name}" has no classes`);
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// console.warn(`No parent div found for field name="${field_name}"`);
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// console.warn(`No field found with name="${field_name}"`);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// function addRequiredFieldSymbolByClass(className) {
|
||||||
|
// // Find all divs with the specified class
|
||||||
|
// var $divsWithClass = $(`.${className}`);
|
||||||
|
|
||||||
|
// if ($divsWithClass.length) {
|
||||||
|
// // Add asterisk to all labels within these divs
|
||||||
|
// $divsWithClass.each(function() {
|
||||||
|
// var $label = $(this).find('label');
|
||||||
|
// if ($label.length && !$label.find('.text-danger').length) {
|
||||||
|
// $label.append(' <span class="text-danger">*</span>');
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
|
||||||
|
// console.log(`Added required symbol to ${$divsWithClass.length} labels with class "${className}"`);
|
||||||
|
// } else {
|
||||||
|
// console.warn(`No divs found with class="${className}"`);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
</script>
|
</script>
|
||||||
Loading…
Reference in New Issue
Block a user