This commit is contained in:
Ross
2025-12-09 21:50:04 +00:00
parent 4011fa3627
commit 1ce1b75739
2 changed files with 25 additions and 2 deletions
@@ -1,6 +1,9 @@
{% load crispy_forms_tags %}
<form method="post" hx-post="{{ form_action }}" hx-target="#constraint-row-{{ initial.key|default:"new" }}" hx-swap="outerHTML">
{% csrf_token %}
{% if error %}
<div class="notification is-danger">{{ error }}</div>
{% endif %}
<div class="field">
<label class="label">Key</label>
<div class="control">
+22 -2
View File
@@ -506,7 +506,18 @@ def rota_option_inline(request, rota_id):
val = request.POST.get("value", "")
vtype = request.POST.get("type", "string")
if not key:
return HttpResponseBadRequest("Key is required")
# Re-render the inline form with an error message
initial = {"key": key, "value": val, "type": vtype}
inline_html = render_to_string(
"rota/partials/rota_option_inline.html",
{"form_action": reverse("rota:rota_option_inline", args=(rota.id,)), "initial": initial, "error": "Key is required", "rota": rota},
request=request,
)
return HttpResponse(inline_html)
# Try to parse according to type; on failure re-render form with error
parsed = None
parse_error = None
try:
if vtype == "int":
parsed = int(val)
@@ -519,7 +530,16 @@ def rota_option_inline(request, rota_id):
else:
parsed = val
except Exception as exc:
return HttpResponseBadRequest(f"Invalid value: {exc}")
parse_error = str(exc)
if parse_error:
initial = {"key": key, "value": val, "type": vtype}
inline_html = render_to_string(
"rota/partials/rota_option_inline.html",
{"form_action": reverse("rota:rota_option_inline", args=(rota.id,)), "initial": initial, "error": f"Invalid value: {parse_error}", "rota": rota},
request=request,
)
return HttpResponse(inline_html)
opts = rota.options or {}
opts[key] = parsed