diff --git a/djangorota/rota/views.py b/djangorota/rota/views.py
index ef9bbd2..4a0b0c7 100644
--- a/djangorota/rota/views.py
+++ b/djangorota/rota/views.py
@@ -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