Permalink
Browse files

So yeah... JS is needed for AJAX... who would have guessed

  • Loading branch information...
1 parent 1cd5e5a commit fe97108cc3458ac2ebf239c992ef56d4c1a4e34c Authmillenon committed Mar 13, 2012
Showing with 43 additions and 0 deletions.
  1. +43 −0 static/js/give.js
View
@@ -0,0 +1,43 @@
+var host = window.location.host
+
+$(document).ready(function() {
+ // AJAX Login
+ $("#id_login").submit(function(event) {
+ var form = $(this);
+ var data = form.serialize();
+ var action = form.find("input[name=ajax_action]").val();
+ var next = form.find("input[name=next]").val();
+
+ $.post(action, data, function(errors) {
+ if (errors) {
+ form.find("* :input").each(function(i) {
+ var selector = "ul#"+$(this).attr("name")+"-errors"
+ form.find("ul#"+$(this).attr("name")+"-errors").remove();
+ })
+ form.find("ul#login-all-errors").remove();
+ for (var field in errors) {
+ var errorlist = '<ul id="login-' + field +
+ '-errors" class="errorlist"></ul>';
+ if (field == 'all') {
+ form.append(errorlist);
+ } else {
+ form.find("input#id_login-"+field+"+br")
+ .after(errorlist);
+ }
+ for (var i in errors[field]) {
+ var selector = "ul#login-"+field+"-errors"
+ form.find(
+ "ul#login-"+field+"-errors"
+ ).append('<li>'+errors[field][i]+'</li>')
+ }
+ }
+ } else {
+ window.location.replace(next);
+ }
+ }).error(function(response) {
+ $('html').html(response.responseText);
+ });
+
+ return false;
+ })
+})

0 comments on commit fe97108

Please sign in to comment.