Skip to content

Improving django-uni-form ajax validation#13

Open
maraujop wants to merge 1 commit intoalex:masterfrom
maraujop:master
Open

Improving django-uni-form ajax validation#13
maraujop wants to merge 1 commit intoalex:masterfrom
maraujop:master

Conversation

@maraujop
Copy link

  • Adding non_field_errors
  • Small bug fix, that broke validation when having a field named length

* Adding non_field_errors
* Small bug fix, that broke validation when having a field named `length`
@jawaidss
Copy link

First of all, thanks to Alex for a great project--I've been using django-ajax-validation for a long time with great success. Secondly, thanks to Miguel for his fork of it improving compatibility with django-uni-form; when I started using Uni-Form, some of my AJAX validation broke, but this fixed it. I've finally tried out Twitter Bootstrap and django-crispy-forms, and they're awesome. However, they don't immediately work with django-ajax-validation, so I modeled a bootstrap_callback function after both of your uniform_callback functions. If anyone else still uses django-ajax-validation, they may find it useful.

function bootstrap_callback(data, form) {
    $(form).find(".alert-error").remove();
    var field_divs = $(form).find(".control-group").filter(".error");
    field_divs.removeClass("error");
    field_divs.find("[id^=error_1_]").remove();
    $.each(data.errors, function(key, val) {
        if (key == "__all__") {
            $(form).prepend('<div class="alert alert-block alert-error"><ul></ul></div>');
            $.each(val, function(key, error) {
                $(".alert-error ul").append("<li>" + error + "</li>");
            });
        } else {
            var field_div = $(form).find(".control-group").filter("#div_" + key);
            field_div.addClass("error");
            field_div.children(".controls").append('<span id="error_1_' + key + '" class="help-inline"><strong>' + val + "</strong></span>");
        }
    });
}

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

Successfully merging this pull request may close these issues.

2 participants