Skip to content

Commit 6313da1

Browse files
authored
Merge pull request #131 from netgrif/NAE-1741
[NAE-1741] 'Undefined' error on frontend when checking i18n translation equality
2 parents f74e303 + 287464d commit 6313da1

File tree

1 file changed

+4
-4
lines changed
  • projects/netgrif-components-core/src/lib/data-fields/i18n-field/models

1 file changed

+4
-4
lines changed

projects/netgrif-components-core/src/lib/data-fields/i18n-field/models/i18n-field.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ export class I18nField extends DataField<I18nFieldValue> {
3636
}
3737

3838
private static translationsEquality(a: I18nFieldValue, b: I18nFieldValue): boolean {
39-
const aKeys = Object.keys(a.translations).sort();
40-
const bKeys = Object.keys(b.translations).sort();
39+
const aKeys = !!a.translations ? Object.keys(a.translations).sort() : [];
40+
const bKeys = !!b.translations ? Object.keys(b.translations).sort() : [];
4141
if (aKeys.length !== bKeys.length
4242
|| !aKeys.every((element, index) => {
4343
return element === bKeys[index];
@@ -166,14 +166,14 @@ export class I18nField extends DataField<I18nFieldValue> {
166166
private validTranslationRequired(countries: Array<string>): ValidatorFn {
167167
return (fc: FormControl): { [key: string]: any } | null => {
168168
return countries.every(languageCode => languageCode in fc.value.translations)
169-
? (null) : ({translationRequired: true});
169+
? null : ({translationRequired: true});
170170
};
171171
}
172172

173173
private validTranslationOnly(countries: Array<string>): ValidatorFn {
174174
return (fc: FormControl): { [key: string]: any } | null => {
175175
return Object.keys(fc.value.translations).every(translation => countries.includes(translation))
176-
? (null) : ({translationOnly: true});
176+
? null : ({translationOnly: true});
177177
};
178178
}
179179

0 commit comments

Comments
 (0)