It would be useful if there were an equivalent function as djangoForm.setErrors for success messages.
It seems strange there is a standard api for form error messages, but only a standard for the success_url. I would have thought it to be a fairly common requirement to have a success feedback message instead of a redirect for forms embedded in a page?
I have needed to do this:
angular.module('subscribe', ['djng.forms']).controller('SubscribeCtrl', function($scope, $http, $window, djangoForm) {
// Provide feedback on successful page load
$scope.success_message = "{{ form.confirm_success }}";
$scope.submit = function() {
if ($scope.subscription_data) {
// Clear any success message before we post
$scope.success_message = "";
$http.post(".", $scope.subscription_data).success(function(out_data) {
// Must return status 2xx for valid and invalid forms
if (!djangoForm.setErrors($scope.subscription_form, out_data.errors)) {
// There were no errors - set the success message if any
if (out_data.success_message) {
$scope.subscription_form.$setPristine();
$scope.success_message = out_data.success_message;
}
//$window.location.href = out_data.success_url;
}
//console.log(out_data);
}).error(function(out_data) {
console.error('An error occurred during subscription submission');
});
}
return false;
};
});
It would be useful if there were an equivalent function as
djangoForm.setErrors
for success messages. It seems strange there is a standard api for form error messages, but only a standard for the success_url. I would have thought it to be a fairly common requirement to have a success feedback message instead of a redirect for forms embedded in a page?I have needed to do this: