Skip to content

Commit 0ee8672

Browse files
authored
fix piece filter with undefined choices (#5078)
1 parent 4c52d4b commit 0ee8672

2 files changed

Lines changed: 10 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
### Fixes
1313

1414
* Fixes a bug in the login `uponSubmit` filter where a user could login without meeting the requirement.
15+
* Fixes pieces filters when values from optional fields are falsy.
1516

1617
### Fixes
1718

modules/@apostrophecms/schema/index.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2101,13 +2101,15 @@ module.exports = {
21012101
const allChoices = await self.getChoices(req, field);
21022102
const values = await query.toDistinct(field.name);
21032103

2104-
const choices = _.map(values, function (value) {
2105-
const choice = _.find(allChoices, { value });
2106-
return {
2107-
value,
2108-
label: choice && (choice.label || value)
2109-
};
2110-
});
2104+
const choices = values
2105+
.filter(Boolean)
2106+
.map(value => {
2107+
const choice = _.find(allChoices, { value });
2108+
return {
2109+
value,
2110+
label: choice && (choice.label || value)
2111+
};
2112+
});
21112113

21122114
self.apos.util.insensitiveSortByProperty(choices, 'label');
21132115

0 commit comments

Comments
 (0)