Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FormDetail view render_to_response returns all ajax requests as code-200 requests #175

Closed
Doskious opened this issue Jan 20, 2016 · 1 comment

Comments

@Doskious
Copy link

Line 72 currently causes all ajax-delivered POST requests to uniformly generate HTTP 200 responses, rather than returning an HttpResponseBadRequest with the same content in the event that there are errors. Currently, this means that anyone submitting an ajax request must create event handlers to inspect the errors json object in the receiving browser, in addition to the standard metrics of readystate and response status. This also means that when using a library, such as jQuery, library-standard detection of form errors on ajax calls will not work.

To permit the ajax handlers to rely exclusively on the readystate and response status for determination of an error, Line 72 could be replaced with the following 4 lines:

response = HttpResponse(json_context, content_type="application/json")
if context["form_for_form"].errors:
    response = HttpResponseBadRequest(json_context, content_type="application/json")
return response

(Assuming, of course, that HttpResponseBadRequest is also imported on line 8.)

Presumably, if this setting needed to be able to be designated per-form, rather than globally, an additional setting could be added to the Form model and checked against in the if-clause...

@stephenmcd
Copy link
Owner

Can you create a PR with the above change? Please don't add any settings at this stage. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants