Merge "Allow optional default value in noValue filter"
This commit is contained in:
commit
b7fd639b34
@ -127,13 +127,14 @@
|
|||||||
* @ngdoc filter
|
* @ngdoc filter
|
||||||
* @name noValue
|
* @name noValue
|
||||||
* @description
|
* @description
|
||||||
* Replaces null / undefined / empty string with translated '-'.
|
* Replaces null / undefined / empty string with translated '-' or the optional
|
||||||
|
* default value provided.
|
||||||
*/
|
*/
|
||||||
function noValueFilter() {
|
function noValueFilter() {
|
||||||
return function (input) {
|
return function (input, def) {
|
||||||
if (input === null || angular.isUndefined(input) ||
|
if (input === null || angular.isUndefined(input) ||
|
||||||
(angular.isString(input) && '' === input.trim())) {
|
(angular.isString(input) && '' === input.trim())) {
|
||||||
return gettext('-');
|
return def || gettext('-');
|
||||||
} else {
|
} else {
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
@ -151,6 +151,15 @@
|
|||||||
expect(noValueFilter('')).toBe('-');
|
expect(noValueFilter('')).toBe('-');
|
||||||
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 () {
|
describe('noName', function () {
|
||||||
|
Loading…
Reference in New Issue
Block a user