<form
    hx-post="{% if form.instance.pk %}{% url 'atlas:case_displaysets_edit' form.instance.pk %}{% else %}{% url 'atlas:case_displaysets_add' case.pk %}{% endif %}"
    {% if form.instance.pk %}
    hx-swap="outerHTML"
    hx-target="closest li"
    {% else %}
    hx-target="#display-set-list"
    hx-swap="beforeend"
    hx-on::after-request= "this.remove()"
    {% endif %}

>
    {% csrf_token %}
    {{ form.as_p }}
    {{ form.media }}
    <input type="hidden" name="viewerstate" id="viewerstate-input">
    <input type="hidden" name="annotations" id="annotations-input">
    <button type="submit">Save</button>
</form>