Skip to content

Commit

Permalink
The Remove Item action disappears for a Dropdown item when its value …
Browse files Browse the repository at this point in the history
…is set to 0 fix #5500
  • Loading branch information
andrewtelnov committed May 15, 2024
1 parent ff86710 commit 1963a69
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/survey-creator-core/src/components/item-value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ export class ItemValueWrapperViewModel extends Base {
if(!Helpers.isNumber(val)) return false;
const min = this.question.choicesMin;
const max = this.question.choicesMax;
if(!Helpers.isNumber(min) || !Helpers.isNumber(max)) return false;
if(!Helpers.isNumber(min) || !Helpers.isNumber(max) || min === max && min === 0) return false;
return val >= min && val <= max;
}
}
26 changes: 26 additions & 0 deletions packages/survey-creator-core/tests/components.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,32 @@ test("Allow remove for choices and generated choices", () => {
expect(generatedItemAdorner.allowAdd).toBeFalsy();
expect(generatedItemAdorner.allowRemove).toBeFalsy();
});
test("Allow remove for choices with value equals to 0, Bug#5500", () => {
const creator = new CreatorTester();
creator.JSON = {
elements: [{ type: "dropdown", name: "q1", choices: [0, 1, 2] }]
};
const question = <QuestionCheckboxModel>creator.survey.getAllQuestions()[0];

const choiceItem1Adorner = new ItemValueWrapperViewModel(creator, question, question.choices[0]);
const choiceItem2Adorner = new ItemValueWrapperViewModel(creator, question, question.choices[1]);
const choiceItem3Adorner = new ItemValueWrapperViewModel(creator, question, question.choices[2]);
expect(choiceItem1Adorner.item.value).toBe(0);
expect(choiceItem1Adorner.isNew).toBeFalsy();
expect(choiceItem1Adorner.allowAdd).toBeFalsy();
expect(choiceItem1Adorner.allowRemove).toBeTruthy();

expect(choiceItem2Adorner.item.value).toBe(1);
expect(choiceItem2Adorner.isNew).toBeFalsy();
expect(choiceItem2Adorner.allowAdd).toBeFalsy();
expect(choiceItem2Adorner.allowRemove).toBeTruthy();

expect(choiceItem3Adorner.item.value).toBe(2);
expect(choiceItem3Adorner.isNew).toBeFalsy();
expect(choiceItem3Adorner.allowAdd).toBeFalsy();
expect(choiceItem3Adorner.allowRemove).toBeTruthy();

});

test("item value allowRemove on events", () => {
const creator = new CreatorTester();
Expand Down

0 comments on commit 1963a69

Please sign in to comment.