What way or method can be used to disable the leave type in the options?
Because in the console, it says that the leave type is already disabled, but it’s still visible in the options and can be clicked or selected. How can this be blocked?
here is the screenshot of the console saying it is disabling the leave type
this is the screenshot of the option but it still visible to pick enter image description here
this is the code i tried using to disable the leave type option
if (employeeInfo.permanent_status == 1 && today > allowedLeaveStartDate) {
var disabledValues = ['1', '5']; // Values to be disabled
console.log('Disabling leave types:', disabledValues);
$("#leaveTypeDropdown option").filter(function() {
return disabledValues.includes($(this).val());
}).prop('disabled', true);
}
i expect it will be blocked or disable the leave type, i don’t know what is wrong, please help.
this is the whole code i’m using, the permanent status 0 is for new employee and the permanent status 1 is for regular employee
<script>
$(document).ready(function () {
var originalLeaveTypes = {!! json_encode($leaveTypeList) !!};
function updateLeaveTypes(selectedEmployeeId) {
$('#leaveTypeDropdown').empty();
// Add a placeholder option
$('#leaveTypeDropdown').append('<option value="">----Please select----</option>');
if (!selectedEmployeeId) {
$.each(originalLeaveTypes, function (index, leaveType) {
$('#leaveTypeDropdown').append('<option value="' + index + '">' + leaveType + '</option>');
});
return;
}
// Continue with the existing logic for updating leave types
$.ajax({
url: '/getEmployeeInfo/' + selectedEmployeeId ,
type: 'GET',
success: function (employeeInfo) {
var excludedLeaveTypeIds = [];
var allowedLeaveStartDate = '{{ $allowedLeaveStartDate }}';
var today = '{{ CarbonCarbon::now() ->toDateString() }}';
console.log('Allowed Leave Start Date:', allowedLeaveStartDate);
console.log('Today:', today);
// Additional condition for excluding leave types based on nationality, department ID, and permanent_status
if (employeeInfo.permanent_status == 0 ) {
excludedLeaveTypeIds = [1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13]; // Hide all leave types except 8
} else if (
employeeInfo.nationality == 1 &&
(employeeInfo.department_id == 29 || employeeInfo.department_id == 32 || employeeInfo.department_id == 33 || employeeInfo.department_id == 34 || employeeInfo.department_id == 36 || employeeInfo.department_id == 37 || employeeInfo.department_id == 38 || employeeInfo.department_id == 39 || employeeInfo.department_id == 62 || employeeInfo.department_id == 63 || employeeInfo.department_id == 64 || employeeInfo.department_id == 68 || employeeInfo.department_id == 69 || employeeInfo.department_id == 71 || employeeInfo.department_id == 72)
) {
excludedLeaveTypeIds = [6, 4, 2, 12, 13];
} else if (
employeeInfo.nationality == 1 &&
!(employeeInfo.department_id == 29 || employeeInfo.department_id == 32 || employeeInfo.department_id == 33 || employeeInfo.department_id == 34 || employeeInfo.department_id == 36 || employeeInfo.department_id == 37 || employeeInfo.department_id == 38 || employeeInfo.department_id == 39 || employeeInfo.department_id == 62 || employeeInfo.department_id == 63 || employeeInfo.department_id == 64 || employeeInfo.department_id == 68 || employeeInfo.department_id == 69 || employeeInfo.department_id == 71 || employeeInfo.department_id == 72)
) {
excludedLeaveTypeIds = [6, 4, 2, 12, 13];
} else if (employeeInfo.nationality >= 2 && employeeInfo.nationality <= 5) {
excludedLeaveTypeIds = [3, 1, 5, 12, 13];
} else if (employeeInfo.nationality >= 6 && employeeInfo.nationality <= 10) {
excludedLeaveTypeIds = [3, 1, 5, 6, 2];
}
if (employeeInfo.permanent_status == 1 && today > allowedLeaveStartDate) {
var disabledValues = ['1', '5']; // Values to be disabled
console.log('Disabling leave types:', disabledValues);
$("#leaveTypeDropdown option").filter(function() {
return disabledValues.includes($(this).val());
}).prop('disabled', true);
}
// Filter and append leave types based on the exclusion list
$.each(originalLeaveTypes, function (index, leaveType) {
var leaveTypeId = parseInt(index);
if (excludedLeaveTypeIds.indexOf(leaveTypeId) === -1 ) {
$('#leaveTypeDropdown').append('<option value="' + leaveTypeId + '">' + leaveType + '</option>');
}
});
},
error: function () {
console.log('Error fetching employee information.');
}
});
}
$('#employeeDropdown').change(function () {
updateLeaveTypes($(this).val());
});
// Trigger the change event initially to set the initial leave type options
$('#employeeDropdown').trigger('change');
});
</script>