Files
ihrm/base/templates/shift_request/allocation_request_update_form.html
2024-05-02 14:49:24 +05:30

40 lines
1.1 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")
$.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
reallocateToSelect.append('<option value="' + employee[0] + '">' + employee[1] + ' ' + employee[2] + '</option>');
}
}
});
});
</script>