Whenever I submit an empty form through my Angular application, the JSON being sent is as follows:
{foo: {}}
This causes a 500 error to occur on my server instead of the expected 422 error, since the server requires the following structure:
{foo: {bar: ""}}
Is there a way to ensure that the "bar" key is always present in the JSON even if its value is empty?
Below is the current state of my controller:
$scope.baz = {};
$scope.create = function() {
var error, success;
$scope.errors = {};
success = function() {
$scope.baz = {};
};
error = function(result) {
angular.forEach(result.data.errors, function(errors, field) {
$scope.form[field].$setValidity('server', false);
$scope.errors[field] = errors.join(', ');
});
};
Foo.save({ foo: { bar: $scope.baz.bar }}).$promise.then(success, error);
};