Created
March 18, 2012 22:24
-
-
Save nowk/2083155 to your computer and use it in GitHub Desktop.
Formtastic errors w/ ajax + knockout.js and responds_to :json
This file contains hidden or 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
$.ajax({ | |
error: function(jqXHR, textStatus, errorThrown) { | |
// reset | |
$('.formtastic li').removeClass("error"); | |
$('.formtastic li .inline-errors').remove(); | |
// set the errors | |
// TODO turn into dynamic | |
// TODO include errors for :base and #semantic_errors | |
var errors = ko.mapping.toJS(ko.mapping.fromJSON(jqXHR.responseText)); | |
$.each(errors, function(key, value) { | |
$(".formtastic.menu li#menu_"+key+"_input.required").addClass("error"); | |
$(".formtastic.menu li#menu_"+key+"_input.required").append('<p class="inline-errors">'+value.join(", ")+'</p>'); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment