From f980d5daa3d64a294acbc5a68d5f4af0e03f5fa5 Mon Sep 17 00:00:00 2001 From: Horilla Date: Sat, 5 Jul 2025 15:39:50 +0530 Subject: [PATCH] [UPDT] HORILLA: Prevent duplicate select2 event triggers on HTMX updates --- .../biometric_users/dahua/add_dahua_user.html | 7 ----- biometric/views.py | 4 +-- helpdesk/templates/helpdesk/faq/load_faq.html | 4 +-- .../emp_objective_create_form.html | 8 ------ .../cbv/timesheet/employee_field.html | 9 ------- .../templates/cbv/timesheet/task_field.html | 8 ------ .../pipeline_components/send_mail.html | 4 --- static/build/js/htmxSelect2.js | 26 ++++++++++++------- 8 files changed, 21 insertions(+), 49 deletions(-) diff --git a/biometric/templates/biometric_users/dahua/add_dahua_user.html b/biometric/templates/biometric_users/dahua/add_dahua_user.html index 7d741defc..c7e16d921 100644 --- a/biometric/templates/biometric_users/dahua/add_dahua_user.html +++ b/biometric/templates/biometric_users/dahua/add_dahua_user.html @@ -24,10 +24,3 @@ - diff --git a/biometric/views.py b/biometric/views.py index 1dc6dec05..26789d4d0 100644 --- a/biometric/views.py +++ b/biometric/views.py @@ -2322,9 +2322,9 @@ def zk_biometric_attendance_bulk_logs(devices): datetime=date_time, ) try: - if punch_code in {0, 3, 4, 5}: + if punch_code in {0, 3, 4}: clock_in(request_data) - elif punch_code in {1, 2}: + elif punch_code in {1, 2, 5}: clock_out(request_data) except Exception as error: logger.error( diff --git a/helpdesk/templates/helpdesk/faq/load_faq.html b/helpdesk/templates/helpdesk/faq/load_faq.html index b9b3793a1..63eb15458 100644 --- a/helpdesk/templates/helpdesk/faq/load_faq.html +++ b/helpdesk/templates/helpdesk/faq/load_faq.html @@ -22,7 +22,7 @@ {% for cat_id, category in catagories.items %}
{{category}}
-
\ No newline at end of file + diff --git a/pms/templates/okr/emp_objective/emp_objective_create_form.html b/pms/templates/okr/emp_objective/emp_objective_create_form.html index b729a30da..6bf35ca2d 100644 --- a/pms/templates/okr/emp_objective/emp_objective_create_form.html +++ b/pms/templates/okr/emp_objective/emp_objective_create_form.html @@ -20,11 +20,3 @@ {{form.as_p}}
- - diff --git a/project/templates/cbv/timesheet/employee_field.html b/project/templates/cbv/timesheet/employee_field.html index 80f3e70d2..a5ac10741 100644 --- a/project/templates/cbv/timesheet/employee_field.html +++ b/project/templates/cbv/timesheet/employee_field.html @@ -3,14 +3,6 @@ title="{{ form.employee_id.help_text|safe }}">{% trans form.employee_id.label %} {{form.employee_id}} diff --git a/project/templates/cbv/timesheet/task_field.html b/project/templates/cbv/timesheet/task_field.html index 418b90fb3..03c529e5f 100644 --- a/project/templates/cbv/timesheet/task_field.html +++ b/project/templates/cbv/timesheet/task_field.html @@ -5,11 +5,3 @@
{{form.task_id}}
- diff --git a/recruitment/templates/pipeline/pipeline_components/send_mail.html b/recruitment/templates/pipeline/pipeline_components/send_mail.html index 6e6d07959..02fa6f692 100644 --- a/recruitment/templates/pipeline/pipeline_components/send_mail.html +++ b/recruitment/templates/pipeline/pipeline_components/send_mail.html @@ -134,10 +134,6 @@ var selectedIds = JSON.parse($("#selectedInstances").attr("data-ids")); $("#candidates[name=candidates]select[multiple]").val(selectedIds).change(); {% endif %} - - $("select").on("select2:select", function (e) { - $(this).closest("select")[0].dispatchEvent(new Event("change")); - }); }); document.querySelector('.submit-send').onclick = function (event) { diff --git a/static/build/js/htmxSelect2.js b/static/build/js/htmxSelect2.js index 64f3de60f..051003ca0 100644 --- a/static/build/js/htmxSelect2.js +++ b/static/build/js/htmxSelect2.js @@ -3999,17 +3999,25 @@ }); staticUrl = $("#statiUrl").attr("data-url"); -$(document).on("htmx:afterRequest", function (event, data) { - var response = event.detail.xhr.response; - var target = $(event.detail.elt.getAttribute("hx-target")); - target.find(".oh-select").select2(); +$(document).ready(function () { + $(".oh-select").select2({ + width: '100%' + }); + $("select").on("select2:select", function (e) { + $(this).closest("select")[0].dispatchEvent(new Event("change")); + }); +}) + +$(document).on("htmx:afterSettle", function (event) { + var target = $(event.target); + target.find(".oh-select").select2({ width: '100%' }); + + target.find("select").off("select2:select").on("select2:select", function (e) { + this.dispatchEvent(new Event("change")); + console.log('__11___'); + }); }); -$(document).on("htmx:afterSettle", function (event, data) { - var response = event.detail.xhr.response; - target = $(event.target); - target.find(".oh-select").select2(); -}); // Helper function to hash data using SHA-256 async function hashData(data) {