Efficient way to avoid empty value?
Specifically, with AngularJS 1.x and a form, my code goes like this:
$scope.settings = { };
$scope.post_social = function() {
var ref = new Firebase(path);
ref.update({
twitter: $scope.settings.twitter,
facebook: $scope.settings.facebook,
google: $scope.settings.google
});
toaster.pop('success', "System", "Settings saved!");
};
This works perfectly fine on Chrome Latest for OS X - but a Windows user, Chrome Latest, reported that this form throws an error if any of the 3 fields are empty, which causes me to change the code to this:
$scope.post_social = function() {
var ref = new Firebase(path);
ref.update({
twitter: ($scope.settings.twitter ? $scope.settings.twitter : ""),
facebook: ($scope.settings.facebook ? $scope.settings.facebook : ""),
google: ($scope.settings.google ? $scope.settings.google : "")
});
toaster.pop('success', "System", "Settings saved!");
};
Firebase (my version of the framework anyways) doesn't allow an empty value; so without the inline if statement, it fails.
Is there an easy way to ensure all items in an object are at the least, not empty without having to do an inline if for each ?