Skip to content

Commit 942c201

Browse files
authored
Merge pull request #149 from netgrif/NAE-1766
[NAE-1766] Options on multichoice autocomplete do not refresh in a specific situation
2 parents 40b5f93 + d043700 commit 942c201

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

projects/netgrif-components-core/src/lib/data-fields/multichoice-field/multichoice-autocomplete-field/abstract-multichoice-autocomplete-field-component.component.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import {FormControl} from '@angular/forms';
44
import {WrappedBoolean} from '../../data-field-template/models/wrapped-boolean';
55
import {COMMA, ENTER} from '@angular/cdk/keycodes';
66
import {MatChipInputEvent} from '@angular/material/chips';
7-
import {Observable, of} from 'rxjs';
8-
import {map, startWith} from 'rxjs/operators';
7+
import {Observable, of, Subscription} from 'rxjs';
98
import {MultichoiceAutocompleteFilterProperty} from './multichoice-autocomplete-filter-property';
109

1110
@Component({
@@ -21,23 +20,26 @@ export abstract class AbstractMultichoiceAutocompleteFieldComponentComponent imp
2120

2221
separatorKeysCodes: number[] = [ENTER, COMMA];
2322

23+
subscriptionChangeData$: Subscription;
24+
2425
filteredOptions: Observable<Array<MultichoiceFieldValue>>;
2526

2627
ngOnInit() {
27-
this.filteredOptions = this.formControlRef.valueChanges.pipe(
28-
startWith(''),
29-
map(value => this._filter(value).filter((option) => !this.multichoiceField.value.includes(option.key)))
30-
);
28+
this.subscriptionChangeData$ =this.formControlRef.valueChanges.subscribe(newVal => {
29+
this.filteredOptions = of(this._filter(newVal ?? '').filter((option) => !this.multichoiceField.value?.includes(option.key)));
30+
})
3131
}
3232

3333
ngOnDestroy(): void {
3434
this.filteredOptions = undefined;
35+
this.subscriptionChangeData$.unsubscribe();
3536
}
3637

3738
add(event: MatChipInputEvent): void {
38-
const value = (event['key'] || '').trim();
39+
const value = event['key'] ?? '';
3940

4041
if (value) {
42+
this.multichoiceField.value = this.multichoiceField.value === null ? [] : this.multichoiceField.value
4143
const choiceArray = [...this.multichoiceField.value];
4244
choiceArray.push(value);
4345
this.multichoiceField.value = choiceArray;

projects/netgrif-components-core/src/lib/task-content/services/task-content.service.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,20 +342,20 @@ export abstract class TaskContentService implements OnDestroy {
342342
private isFieldInTaskRef(changedField: string): boolean {
343343
return !!this.taskFieldsIndex &&
344344
Object.keys(this.taskFieldsIndex)
345-
.some(taskId => taskId !== this.task.stringId && this.taskFieldsIndex[taskId].fields[changedField]);
345+
.some(taskId => taskId !== this.task.stringId && this.taskFieldsIndex[taskId].fields[changedField]);
346346
}
347347

348348
private getReferencedTransitionId(changedField: string): string {
349349
if (!!this.taskFieldsIndex) {
350-
const taskFieldsIndexId = this.getReferencedFieldTask(changedField);
351-
return this.taskFieldsIndex[taskFieldsIndexId].transitionId;
350+
const taskFieldsIndexId = this.getReferencedFieldTask(changedField);
351+
return this.taskFieldsIndex[taskFieldsIndexId].transitionId;
352352
}
353353
return undefined;
354354
}
355355

356356
private getReferencedTaskId(changedField: string): string {
357357
if (!!this.taskFieldsIndex) {
358-
return Object.keys(this.taskFieldsIndex).find(taskId =>
358+
return Object.keys(this.taskFieldsIndex).find(taskId =>
359359
Object.keys(this.taskFieldsIndex[taskId].fields).includes(changedField));
360360
}
361361
return undefined;

0 commit comments

Comments
 (0)