Allow optional default value in noValue filter
This updates the noValue filter so an optional default value can be provided instead of the '-'. Change-Id: I0fb800407ffc2166c7cda427833bb4dd012c0643
This commit is contained in:
parent
cda9604792
commit
9151b59bc9
@ -126,13 +126,14 @@
|
||||
* @ngdoc filter
|
||||
* @name noValue
|
||||
* @description
|
||||
* Replaces null / undefined / empty string with translated '-'.
|
||||
* Replaces null / undefined / empty string with translated '-' or the optional
|
||||
* default value provided.
|
||||
*/
|
||||
function noValueFilter() {
|
||||
return function (input) {
|
||||
return function (input, def) {
|
||||
if (input === null || angular.isUndefined(input) ||
|
||||
(angular.isString(input) && '' === input.trim())) {
|
||||
return gettext('-');
|
||||
return def || gettext('-');
|
||||
} else {
|
||||
return input;
|
||||
}
|
||||
|
@ -151,6 +151,15 @@
|
||||
expect(noValueFilter('')).toBe('-');
|
||||
expect(noValueFilter(' ')).toBe('-');
|
||||
});
|
||||
|
||||
it('replaces undefined, null, blank with provided value', function () {
|
||||
expect(noValueFilter(null, 'default')).toBe('default');
|
||||
expect(noValueFilter(undefined, 'default')).toBe('default');
|
||||
expect(noValueFilter('', 'default')).toBe('default');
|
||||
expect(noValueFilter(' ', 'default')).toBe('default');
|
||||
expect(noValueFilter('value', 'default')).toBe('value');
|
||||
expect(noValueFilter(false, 'default')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('noName', function () {
|
||||
|
Loading…
Reference in New Issue
Block a user