Files
ihrm/base/templates/shift_request/allocation_request_update_form.html
2024-02-06 17:36:59 +05:30

42 lines
1.2 KiB
HTML

{% load i18n %}
{% load static %}
<form hx-post="{% url 'shift-allocation-request-update' form.instance.id %}"
hx-target="#shiftRequestModalUpdateBody">
{{form.as_p}}
</form>
<script>
$("#id_shift_id").change(function(e){
var selectedElement = $("#id_shift_id")
var selectElement = $("#id_shift_id").val();
let parentForm = selectedElement.parents().closest("form")
console.log(selectElement)
$.ajax({
type: "post",
url: "{% url 'update-employee-allocation' %}",
data: {
csrfmiddlewaretoken: getCookie("csrftoken"),
"shift_id":selectElement
},
success: function (response) {
var reallocateToSelect = parentForm.find("[name=reallocate_to]");
reallocateToSelect.empty(); // Clear existing options
for (var i = 0; i < response.employee_data.length; i++) {
var employee = response.employee_data[i];
// Log the values being added
console.log('Adding option:', employee[0], employee[1]);
reallocateToSelect.append('<option value="' + employee[0] + '">' + employee[1] + ' ' + employee[2] + '</option>');
}
}
});
});
</script>