Skip to content

Commit

Permalink
Ajax error responses. Closes #175.
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenmcd committed Aug 24, 2016
1 parent 35196a5 commit 52be9a3
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion forms_builder/forms/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.conf import settings
from django.contrib.auth import REDIRECT_FIELD_NAME
from django.core.urlresolvers import reverse
from django.http import HttpResponse
from django.http import HttpResponse, HttpResponseBadRequest
from django.shortcuts import get_object_or_404, redirect, render_to_response
from django.template import RequestContext
from django.utils.http import urlquote
Expand Down Expand Up @@ -69,6 +69,9 @@ def render_to_response(self, context, **kwargs):
"form": context["form_for_form"].as_p(),
"message": context["form"].response,
})
if context["form_for_form"].errors:
return HttpResponseBadRequest(json_context,
content_type="application/json")
return HttpResponse(json_context, content_type="application/json")
return super(FormDetail, self).render_to_response(context, **kwargs)

Expand Down

0 comments on commit 52be9a3

Please sign in to comment.