Skip to content

Commit

Permalink
Choices - The new item remains visible after disabling item addition …
Browse files Browse the repository at this point in the history
…using the creator.onCollectionItemAllowOperations event fix #5521 (#5529)
  • Loading branch information
andrewtelnov authored May 27, 2024
1 parent 12018fb commit 68bef95
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/survey-creator-core/src/components/item-value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ export class ItemValueWrapperViewModel extends Base {
for(let key in specificChoices) {
this.registerOnPropertyChanged(key, specificChoices[key]);
}
//this.registerOnPropertyChanged("selectAllItem", "hasSelectAll");
if (this.isNew) {
question.visibleChoicesChangedCallback = () => {
this.updateNewItemValue();
Expand All @@ -69,7 +68,9 @@ export class ItemValueWrapperViewModel extends Base {
if (this.allowItemOperations.allowAdd === undefined) {
this.allowItemOperations.allowAdd = true;
}

if(!this.allowItemOperations.allowAdd) {
this.updateIsNewVisibility();
}
if (!this.creator.isCanModifyProperty(question, "choices")) {
this.canTouchItems = false;
}
Expand Down Expand Up @@ -217,6 +218,12 @@ export class ItemValueWrapperViewModel extends Base {
}
private updateIsNew(question: QuestionSelectBase, item: ItemValue) {
this.isNew = !question.isItemInList(item) && !this.isAutoGeneratedItem(item);
this.updateIsNewVisibility();
}
private updateIsNewVisibility(): void {
if(this.isNew) {
this.item.setIsVisible(!(this.allowItemOperations?.allowAdd === false));
}
}

get allowRemove() {
Expand Down
1 change: 1 addition & 0 deletions packages/survey-creator-core/tests/components.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ test("item value allowAdd on events", () => {
expect(noneAdorner.allowAdd).toBeTruthy();
expect(otherAdorner.allowAdd).toBeFalsy();
expect(newAdorner.allowAdd).toBeFalsy();
expect(newAdorner.item.isVisible).toBeFalsy();
});

test("item value no pointer down on new or editable", (): any => {
Expand Down

0 comments on commit 68bef95

Please sign in to comment.