Repository URL to install this package:
|
Version:
1.0.8 ▾
|
(function() {
'use strict';
angular.module('angularGobox').factory('AddressValidator', AddressValidatorFactory);
function AddressValidatorFactory() {
function AddressValidator(address) {
this.address = addEmptyValues(address);
}
AddressValidator.requiredFields = ['name', 'address1', 'postal_code', 'city'];
AddressValidator.addressFields = ['name', 'tlf', 'address1', 'postal_code', 'city'];
AddressValidator.prototype.invalidFields = function() {
var fields = _.pick(this.address, AddressValidator.requiredFields);
return _.reduce(fields, function(arr, val, key) {
if (!val) arr.push(key);
return arr;
}, []);
}
AddressValidator.prototype.valid = function() {
return this.invalidFields().length == 0;
};
function addEmptyValues(address) {
return angular.extend(_.reduce(AddressValidator.addressFields, function(obj, key) {
obj[key] = ''; return obj;
}, {}), address);
}
return AddressValidator;
}
})();