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

Could not modify dropdown value from survey correctly if choices are … #6434

Merged
merged 1 commit into from
Jun 27, 2023
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
3 changes: 3 additions & 0 deletions src/question_baseselect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1155,6 +1155,9 @@ export class QuestionSelectBase extends Question {
}
}
super.updateValueFromSurvey(newValue);
if((this.isRunningChoices || this.choicesByUrl.isRunning) && !this.isEmpty()) {
this.cachedValueForUrlRequests = this.value;
}
if (!!newComment) {
this.setNewComment(newComment);
}
Expand Down
18 changes: 18 additions & 0 deletions tests/choicesRestfultests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,24 @@ QUnit.test("Set value before loading data, bug #1089", function(assert) {
assert.equal(question.value, "CA", "'CA' value is still here");
assert.equal(question.selectedItem.value, "CA", "selectedItem is correct");
});
QUnit.test("Set value before loading data + defaultValue", function(assert) {
const survey = new SurveyModel();
survey.addNewPage("1");
const question = new QuestionDropdownModelTester("q1");
question.defaultValue = "CA";
question.choicesByUrl.url = "{state}";
survey.pages[0].addQuestion(question);
question.hasItemsCallbackDelay = true;
question.onSurveyLoad();
question.restFulTest.isRequestRunning = true;
assert.equal(question.restFulTest.isRunning, true, "request should be running");
assert.equal(question.value, "CA", "Set default Value");
survey.mergeData({ "q1": "TX" });
question.restFulTest.isRequestRunning = false;
question["onLoadChoicesFromUrl"]([new ItemValue("CA"), new ItemValue("TX")]);
assert.equal(question.value, "TX", "'TX' value is here");
assert.equal(question.selectedItem.value, "TX", "selectedItem is correct");
});
QUnit.test("Clear value on getting empty array, bug #6251", function(assert) {
var survey = new SurveyModel();
survey.addNewPage("1");
Expand Down