Looking for a simple way to enable JSON submissions for your Django forms and modelforms?
Enter jsforms. A simple Django app and jQuery plugin that will allow you to enable JSON submissions while keeping your forms intact for non-JavaScript clients.
I have uploaded the jsforms source code to github
To get it up and running, drop the jsforms app into your Django project or PYTHONPATH, follow the README instructions and copy the static content over to your MEDIA_URL. Then include the jquery-jsforms.min.js file along with a recent version of jQuery in your templates (a symbolic link will work just as well).
For each view that you want to utilize this for, wrap with the jsform decorator. In the view, you will need to add the ajax check and return the form instance. This will allow the decorator to capture the errors.
@jsform()
def view_example(request):
form = SomeForm()
if request.method == 'POST':
form = SomeForm(request.POST)
if form.is_valid():
return HttpResponseRedirect('/success/')
if request.is_ajax():
return form...
Full view example.
In the template, use the jsforms jQuery plugin to enable the integration for each applicable form element.
<script type="text/javascript">
$("form").jsform();
</script>
Full template example.

