Created
February 14, 2013 13:29
-
-
Save felipe-prenholato/4952775 to your computer and use it in GitHub Desktop.
files to use with https://github.com/chronossc/django-cbv-utils/blob/4d992533925e4bc2e215cbfa8e98d07853d65784/cbv_utils/views.py#L152
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% spaceless %} | |
{# this is included in form.html and is loaded via ajax #} | |
{% load bootstrap_toolkit %} | |
{% if success %} | |
{# msg in form instead in next request #} | |
<div class="alert success alert-success"> | |
<a class="close" data-dismiss="alert">×</a> | |
{{ success|safe }} | |
</div> | |
{% endif %} | |
{{ form|as_bootstrap }} | |
{% endspaceless %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- this is original form in html page --> | |
<form method="POST" action="{% url "your_update_form_url" pk=object.pk %}" class="form" id="myform"> | |
<div class="form_fields"> | |
{% with form=user_form %} | |
{% include "user_ajax_form.html" %} | |
{% endwith %} | |
</div> | |
<div class="form_buttons"> | |
<button class="btn btn-primary" name="update" type="submit">Update</button> | |
<button class="btn btn-danger" name="reset">Reset</button> | |
</div> | |
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($) { | |
// untested code, I changed variables names from working code | |
// this js post form via ajax and update .form_fields with rendered form in ajax_form.html | |
var $form = $("#myform"); | |
$form.submit(function(e) { | |
e.preventDefault(); | |
e.stopPropagation(); | |
var $that = $(this); | |
$.post($that.attr('action'), $that.serializeArray(), function(data, status) { | |
$that.find(".form_fields").html(data.form); | |
}); | |
return false; | |
}); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment