Manage backgrounds
diff --git a/cards/views.py b/cards/views.py
index ae3e61a..8a3e464 100644
--- a/cards/views.py
+++ b/cards/views.py
@@ -91,20 +91,22 @@ def card_create(request):
card.save()
if is_htmx(request):
card_html = render_to_string('cards/_card_item.html', {'card': card, 'background': background}, request=request)
- # Also return an out-of-band fragment to replace/clear the form container
- form_html = render_to_string('cards/_form.html', {'form': DinosaurForm(), 'background': background, 'backgrounds': backgrounds}, request=request)
- oob = f'
{form_html}
'
+ # Clear the modal via out-of-band so the modal-root is emptied
+ oob = '
'
return HttpResponse(card_html + oob)
return redirect('cards:list')
else:
if is_htmx(request):
- # Return the form as an out-of-band fragment so it updates the form container
- form_html = render_to_string('cards/_form.html', {'form': form, 'background': background, 'backgrounds': backgrounds}, request=request)
- oob = f'
{form_html}
'
- return HttpResponse(oob)
+ # Return the form wrapped in a modal fragment so it updates the modal-root
+ form_html = render_to_string('cards/_form_modal.html', {'form': form, 'background': background, 'backgrounds': backgrounds}, request=request)
+ return HttpResponse(form_html)
else:
form = DinosaurForm()
+ # If this is an HTMX request, return the modal-wrapped form so it can be
+ # injected into `#modal-root`. Otherwise return the standalone form page.
+ if is_htmx(request):
+ return render(request, 'cards/_form_modal.html', {'form': form, 'background': background, 'backgrounds': backgrounds})
return render(request, 'cards/_form.html', {'form': form, 'background': background, 'backgrounds': backgrounds})
@@ -126,18 +128,19 @@ def card_edit(request, pk):
card.save()
if is_htmx(request):
card_html = render_to_string('cards/_card_item.html', {'card': card, 'background': background}, request=request)
- # Clear the form container via OOB so the edit form disappears after successful save
- oob = '
'
+ # Clear the modal via OOB so the modal-root is emptied
+ oob = '
'
return HttpResponse(card_html + oob)
return redirect('cards:list')
else:
if is_htmx(request):
- form_html = render_to_string('cards/_form.html', {'form': form, 'card': card, 'background': background, 'backgrounds': backgrounds}, request=request)
- oob = f'
{form_html}
'
- return HttpResponse(oob)
+ form_html = render_to_string('cards/_form_modal.html', {'form': form, 'card': card, 'background': background, 'backgrounds': backgrounds}, request=request)
+ return HttpResponse(form_html)
else:
form = DinosaurForm(instance=card)
+ if is_htmx(request):
+ return render(request, 'cards/_form_modal.html', {'form': form, 'card': card, 'background': background, 'backgrounds': backgrounds})
return render(request, 'cards/_form.html', {'form': form, 'card': card, 'background': background, 'backgrounds': backgrounds})
diff --git a/db.sqlite3 b/db.sqlite3
index 93a1822..ae16086 100644
Binary files a/db.sqlite3 and b/db.sqlite3 differ