gorgeous-ghost-95789
01/05/2022, 2:59 PMgorgeous-ghost-95789
01/05/2022, 3:01 PMadamant-exabyte-92636
01/05/2022, 3:03 PMgorgeous-ghost-95789
01/05/2022, 3:03 PMhx-swap=“none”
is important in cases like this. You have a delicate front-end component that already knows the correct state, and doesn’t need any new information from the server. So just post your updates and don’t listen for a response.fresh-controller-36545
01/05/2022, 3:07 PMfresh-controller-36545
01/05/2022, 3:08 PMgorgeous-ghost-95789
01/05/2022, 3:13 PMaloof-xylophone-31768
01/06/2022, 2:24 AMblue-gold-89534
01/06/2022, 12:44 PMplain-kangaroo-26043
01/06/2022, 12:51 PMfresh-judge-74869
01/06/2022, 4:07 PMfresh-controller-36545
01/06/2022, 4:55 PMfresh-controller-36545
01/06/2022, 4:55 PMfresh-judge-74869
01/06/2022, 5:22 PMmysterious-toddler-20573
01/06/2022, 5:29 PMfresh-controller-36545
01/06/2022, 5:35 PMhtml
<!-- book_form_hx.html -->
<div class="modal-header">
<h4 class="modal-title" id="addModalLabel">Adicionar Livro</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
</div>
<form
hx-post="{% url 'bookstore:book_create' %}"
hx-target="#formx"
hx-select="#formx"
hx-swap="outerHTML"
hx-indicator=".htmx-indicator"
hx-swap="afterbegin"
>
<div id="formx" class="modal-body">
{% csrf_token %}
{% for field in form %}
<div class="form-group p-2">
{{ field.label_tag }}
{{ field }}
{{ field.errors }}
{% if field.help_text %}
<small class="text-muted">{{ field.help_text|safe }}</small>
{% endif %}
</div>
{% endfor %}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Fechar</button>
<button type="submit" class="btn btn-primary">Salvar</button>
</div>
</form>
<script>
</script>
On the server-side you can then close the modal by sending a htmx header or using e.g. hyperscript
.fresh-controller-36545
01/06/2022, 5:37 PMmysterious-toddler-20573
01/06/2022, 5:39 PMlively-traffic-17360
01/06/2022, 5:43 PMmysterious-toddler-20573
01/06/2022, 5:50 PMlively-traffic-17360
01/06/2022, 5:50 PMlively-traffic-17360
01/06/2022, 5:54 PMlively-traffic-17360
01/06/2022, 5:55 PM{% extends 'core/index.html' %}
{% load static %}
{% block breadcrumb %}
<ol class="breadcrumb float-sm-right">
<li class="breadcrumb-item">
<a href="{% url 'core:index' %}">
<i class="fas fa-home"></i>
Página Inicial
</a>
</li>
<li class="breadcrumb-item active">
Usuários
</li>
</ol>
{% endblock breadcrumb %}
{% block body %}
<div class="col-md-12">
<div class="container-fluid">
<div id="container-usuario-dados"
hx-get="{% url 'usuario:create' %}"
{% if pessoa %}
hx-vals='{"usuario_id": "{{ usuario.id }}"}'
{% endif %}
hx-trigger="load"
hx-swap="innerHTML">
</div>
<div id="container-usuario-list"
hx-get="{% url 'usuario:list' %}"
{% if pessoa %}
hx-vals='{"usuario_id": "{{ usuario.id }}"}'
{% endif %}
hx-trigger="load, hx-list-updated from:body"
hx-swap="innerHTML">
</div>
</div>
{% comment %} {% include 'usuarios/list.html' %} {% endcomment %}
</div>
{% endblock body %}
{% block extra_javascript %}
<!--HTMX-->
<script src="https://unpkg.com/htmx.org@1.6.0" crossorigin="anonymous"
integrity="sha384-G4dtlRlMBrk5fEiRXDsLjriPo8Qk5ZeHVVxS8KhX6D7I9XXJlNqbdvRlp9/glk5D">
</script>
{% endblock extra_javascript %}
fresh-judge-74869
01/06/2022, 5:55 PMlively-traffic-17360
01/06/2022, 5:56 PMfresh-controller-36545
01/06/2022, 5:57 PMhx-delete
I would've expected for deleting the list element here.fresh-controller-36545
01/06/2022, 5:57 PMreturn context...
. with return HttpResponse(mark_safe('<script>setTimeout(location.reload(), 500)</script>'))
after the form has been saved.lively-traffic-17360
01/06/2022, 5:59 PMlively-traffic-17360
01/06/2022, 6:00 PM