Skip to content

Commit

Permalink
Merge pull request #15169 from primefaces/issue-14698
Browse files Browse the repository at this point in the history
Fixed #14698 - p-cascadeSelect | options: not change after new data i…
  • Loading branch information
cetincakiroglu authored Mar 29, 2024
2 parents d93855a + 7049296 commit 48a3b3b
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/app/components/cascadeselect/cascadeselect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
Output,
QueryList,
signal,
SimpleChanges,
TemplateRef,
ViewChild,
ViewEncapsulation
Expand Down Expand Up @@ -295,7 +296,7 @@ export class CascadeSelectSub implements OnInit {
<div class="p-cascadeselect-items-wrapper" [attr.data-pc-section]="'wrapper'">
<p-cascadeSelectSub
class="p-cascadeselect-items"
[options]="processedOptions()"
[options]="processedOptions"
[selectId]="id"
[focusedOptionId]="focused ? focusedOptionId : undefined"
[activeOptionPath]="activeOptionPath()"
Expand Down Expand Up @@ -618,6 +619,8 @@ export class CascadeSelect implements OnInit, AfterContentInit {

modelValue = signal<any>(null);

processedOptions: string[] | string | undefined = [];

get containerClass() {
return {
'p-cascadeselect p-component p-inputwrapper': true,
Expand Down Expand Up @@ -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(() => {
Expand All @@ -710,6 +709,13 @@ export class CascadeSelect implements OnInit, AfterContentInit {
return label;
}

ngOnChanges(changes: SimpleChanges): void {
if (changes.options) {
this.processedOptions = this.createProcessedOptions(changes.options.currentValue || []);
this.updateModel(null)
}
}

hasSelectedOption() {
return ObjectUtils.isNotEmpty(this.modelValue());
}
Expand Down Expand Up @@ -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 [];
Expand Down

0 comments on commit 48a3b3b

Please sign in to comment.