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

Fix: If choicesByUrl.allowEmptyResponse is true and we have other val… #3010

Merged
merged 1 commit into from
Jun 23, 2021
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
6 changes: 4 additions & 2 deletions src/question_baseselect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,9 @@ export class QuestionSelectBase extends Question {
return true;
}
protected get isAddDefaultItems() {
return settings.supportCreatorV2 && this.isDesignMode && !this.parentQuestion;
return (
settings.supportCreatorV2 && this.isDesignMode && !this.parentQuestion
);
}
public getPlainData(
options: {
Expand Down Expand Up @@ -906,7 +908,7 @@ export class QuestionSelectBase extends Question {
this.cachedValueForUrlRequests,
checkCachedValuesOnExisting
);
if (array && array.length > 0) {
if (array && (array.length > 0 || this.choicesByUrl.allowEmptyResponse)) {
newChoices = new Array<ItemValue>();
ItemValue.setData(newChoices, array);
}
Expand Down
52 changes: 52 additions & 0 deletions tests/choicesRestfultests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,58 @@ QUnit.test("Do not set comments on running values", function(assert) {
assert.notOk(question.comment, "Comment is empty");
});

QUnit.test("Set comment on incorrect value", function(assert) {
var survey = new SurveyModel();
survey.storeOthersAsComment = false;
survey.addNewPage("1");
var question = new QuestionDropdownModelTester("q1");
question.hasOther = true;
question.hasItemsCallbackDelay = true;
question.choicesByUrl.url = "something";
question.choicesByUrl.valueName = "id";
question.restFulTest.items = [{ id: "id1" }, { id: "id2" }, { id: "id3" }];
survey.pages[0].addQuestion(question);
question.restFulTest.isRequestRunning = true;
question.onSurveyLoad();
assert.equal(
question.visibleChoices.length,
1,
"Choices are not loaded yet, we have other"
);
survey.data = { q1: "id_unknown" };
question.restFulTest.isRequestRunning = false;
question.doResultsCallback();
assert.equal(question.value, "id_unknown", "Value is set correctly");
assert.equal(question.comment, "id_unknown");
});
QUnit.test("Set comment on incorrect value and empty results", function(
assert
) {
var survey = new SurveyModel();
survey.storeOthersAsComment = false;
survey.addNewPage("1");
var question = new QuestionDropdownModelTester("q1");
question.hasOther = true;
question.hasItemsCallbackDelay = true;
question.choicesByUrl.url = "something";
question.choicesByUrl.valueName = "id";
question.choicesByUrl.allowEmptyResponse = true;
question.restFulTest.items = [];
survey.pages[0].addQuestion(question);
question.restFulTest.isRequestRunning = true;
question.onSurveyLoad();
assert.equal(
question.visibleChoices.length,
1,
"Choices are not loaded yet, we have other"
);
survey.data = { q1: "id_unknown" };
question.restFulTest.isRequestRunning = false;
question.doResultsCallback();
assert.equal(question.value, "id_unknown", "Value is set correctly");
assert.equal(question.comment, "id_unknown");
});

QUnit.test("Use values and not text, Bug #627", function(assert) {
var survey = new SurveyModel();
survey.addNewPage("1");
Expand Down