Skip to content

Commit

Permalink
fix: Handles forms that was on change
Browse files Browse the repository at this point in the history
fixes #38
  • Loading branch information
lucbelliveau committed May 15, 2023
1 parent cfdd972 commit 9c246fc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions autocomplete/static/autocomplete/js/autocomplete.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
function phac_aspc_autocomplete_trigger_change(container_id) {
setTimeout(() => {
const container = document.getElementById(container_id);
const el = container.querySelector('.textinput');
el.dispatchEvent(new Event('change', { bubbles: true }));
}, 0)
}

function phac_aspc_autocomplete_clear_focus(container, activate_ring) {
const hasFocus = container.querySelectorAll('.hasFocus');
Expand Down
2 changes: 2 additions & 0 deletions autocomplete/templates/autocomplete/component.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
<div
id="{{ component_id }}__container"
class="phac_aspc_form_autocomplete"
{% if htmx_preserve %}
hx-preserve
{% endif %}
>
{% comment %} Hidden input elements used to maintain the component's state {% endcomment %}
{% comment %} and used when submitting forms {% endcomment %}
Expand Down
4 changes: 4 additions & 0 deletions autocomplete/templates/autocomplete/item.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,8 @@
{% endif %}
{% endfor %}
{% endif %}
<script data-componentid="{{ component_id }}">
phac_aspc_autocomplete_trigger_change(document.currentScript.dataset.componentid + '__container');
</script>

{% endif %}

0 comments on commit 9c246fc

Please sign in to comment.