diff --git a/horizon/static/framework/util/filters/filters.js b/horizon/static/framework/util/filters/filters.js index 9ecbc01803..7191c8a1c4 100644 --- a/horizon/static/framework/util/filters/filters.js +++ b/horizon/static/framework/util/filters/filters.js @@ -127,13 +127,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; } diff --git a/horizon/static/framework/util/filters/filters.spec.js b/horizon/static/framework/util/filters/filters.spec.js index d7a23b7063..572dd79026 100644 --- a/horizon/static/framework/util/filters/filters.spec.js +++ b/horizon/static/framework/util/filters/filters.spec.js @@ -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 () {