Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Choices - The new item remains visible after disabling item addition … #5529

Merged
merged 1 commit into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading