Skip to content

Commit 35dad5c

Browse files
committed
fix(query-builder): prevent error when entities are empty and expressionTree is set
getFormat() was calling .pipeArgs.format without optional chaining after find(), causing Angular's ngFormatDate to receive undefined as the format string (TypeError: Cannot read properties of undefined (reading 'length')) when fields is null due to an empty entities array. Added full optional chaining and a DEFAULT_PIPE_DATE_FORMAT fallback.
1 parent 2f824cb commit 35dad5c

2 files changed

Lines changed: 2 additions & 1 deletion

File tree

projects/igniteui-angular/query-builder/src/query-builder/query-builder-tree.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1380,7 +1380,7 @@ export class IgxQueryBuilderTreeComponent implements AfterViewInit, OnDestroy {
13801380
* @hidden @internal
13811381
*/
13821382
public getFormat(field: string) {
1383-
return this.fields?.find(el => el.field === field).pipeArgs.format;
1383+
return this.fields?.find(el => el.field === field)?.pipeArgs?.format ?? DEFAULT_PIPE_DATE_FORMAT;
13841384
}
13851385

13861386
/**

projects/igniteui-angular/query-builder/src/query-builder/query-builder.component.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ describe('IgxQueryBuilder', () => {
2828
IgxQueryBuilderComponent,
2929
IgxQueryBuilderSampleTestComponent,
3030
IgxQueryBuilderCustomTemplateSampleTestComponent,
31+
IgxQueryBuilderInvalidSampleTestComponent,
3132
IgxComboComponent
3233
]
3334
}).compileComponents();

0 commit comments

Comments
 (0)