[UPDT] HORILLA: Prevent duplicate select2 event triggers on HTMX updates

This commit is contained in:
Horilla
2025-07-05 15:39:50 +05:30
parent 5cae06549a
commit f980d5daa3
8 changed files with 21 additions and 49 deletions

View File

@@ -24,10 +24,3 @@
</div>
</form>
</div>
<script>
$(document).ready(function () {
$("select").on("select2:select", function (e) {
$(this).closest("select")[0].dispatchEvent(new Event("change"));
});
});
</script>

View File

@@ -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(

View File

@@ -22,7 +22,7 @@
{% for cat_id, category in catagories.items %}
<div class="oh-accordion">
<div class="oh-accordion-header">{{category}}</div>
<div
<div
class="oh-accordion-body"
style="
max-height: 500px; overflow-y: auto;
@@ -108,4 +108,4 @@
$(".selectAll").click();
});
});
</script>
</script>

View File

@@ -20,11 +20,3 @@
{{form.as_p}}
</form>
</div>
<script>
$(document).ready(function () {
$("select").on("select2:select", function (e) {
$(this).closest("select")[0].dispatchEvent(new Event("change"));
});
});
</script>

View File

@@ -3,14 +3,6 @@
title="{{ form.employee_id.help_text|safe }}">{% trans form.employee_id.label %}</label>
{{form.employee_id}}
<script>
$(document).ready(function () {
$("select").on("select2:select", function (e) {
$(this).closest("select")[0].dispatchEvent(new Event("change"));
});
});
var task_id = "{{ task_id }}"
if (task_id === "dynamic_create") {
var project_id = "{{ project_id }}"
@@ -25,5 +17,4 @@
$(buttonId).click();
}
</script>

View File

@@ -5,11 +5,3 @@
<div id="dynamic_field_task_id">
{{form.task_id}}
</div>
<script>
$(document).ready(function () {
$("select").on("select2:select", function (e) {
$(this).closest("select")[0].dispatchEvent(new Event("change"));
});
});
</script>

View File

@@ -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) {

View File

@@ -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) {