From 5afe84ec2d3a4c1af15467e7ff993a8d6e4fa2df Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mehmet=20=C3=87etin?=
<92744169+mehmetcetin01140@users.noreply.github.com>
Date: Tue, 26 Mar 2024 17:57:26 +0300
Subject: [PATCH] Fixed #14698 - p-cascadeSelect | options: not change after
new data in array of options
---
.../components/cascadeselect/cascadeselect.ts | 20 ++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)
diff --git a/src/app/components/cascadeselect/cascadeselect.ts b/src/app/components/cascadeselect/cascadeselect.ts
index d5ae6d79178..18ed45d13af 100755
--- a/src/app/components/cascadeselect/cascadeselect.ts
+++ b/src/app/components/cascadeselect/cascadeselect.ts
@@ -18,6 +18,7 @@ import {
Output,
QueryList,
signal,
+ SimpleChanges,
TemplateRef,
ViewChild,
ViewEncapsulation
@@ -295,7 +296,7 @@ export class CascadeSelectSub implements OnInit {
(null);
+ processedOptions: string[] | string | undefined = [];
+
get containerClass() {
return {
'p-cascadeselect p-component p-inputwrapper': true,
@@ -679,11 +682,7 @@ export class CascadeSelect implements OnInit, AfterContentInit {
visibleOptions = computed(() => {
const processedOption = this.activeOptionPath().find((p) => p.key === this.focusedOptionInfo().parentKey);
- return processedOption ? processedOption.children : this.processedOptions();
- });
-
- processedOptions = computed(() => {
- return this.createProcessedOptions(this.options || []);
+ return processedOption ? processedOption.children : this.processedOptions;
});
label = computed(() => {
@@ -710,6 +709,13 @@ export class CascadeSelect implements OnInit, AfterContentInit {
return label;
}
+ ngOnChanges(changes: SimpleChanges): void {
+ if (changes.options) {
+ this.processedOptions = this.createProcessedOptions(this.options || []);
+ this.modelValue.set('');
+ }
+ }
+
hasSelectedOption() {
return ObjectUtils.isNotEmpty(this.modelValue());
}
@@ -1074,7 +1080,7 @@ export class CascadeSelect implements OnInit, AfterContentInit {
}
findOptionPathByValue(value, processedOptions?, level = 0) {
- processedOptions = processedOptions || (level === 0 && this.processedOptions());
+ processedOptions = processedOptions || (level === 0 && this.processedOptions);
if (!processedOptions) return null;
if (ObjectUtils.isEmpty(value)) return [];