Upgrade scalatra-forms to support Ajax request.

This commit is contained in:
takezoe
2013-06-28 02:46:18 +09:00
parent a217513205
commit fb11cd6f73
2 changed files with 8 additions and 4 deletions

Binary file not shown.

View File

@@ -13,16 +13,20 @@ function validate(e){
$.post(form.attr('action') + '/validate', $(e.target).serialize(), function(data){
// clear all error messages
$('.error').text('');
$('.error-message').text('');
if($.isEmptyObject(data)){
form.data('validated', true);
form.submit();
} else {
$.each(data, function(key, value){
$('#error-' + key).text(value);
});
displayErrors(data);
}
}, 'json');
return false;
}
function displayErrors(data){
$.each(data, function(key, value){
$('#error-' + key).text(value);
});
}