Skip to content

Commit

Permalink
Do not call isReady for select base quetions with emtpy choices (#7021)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtelnov authored Sep 26, 2023
1 parent cde9938 commit 6181130
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 16 deletions.
8 changes: 1 addition & 7 deletions src/choicesRestful.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,7 @@ export class ChoicesRestful extends Base {
return "choicesByUrl";
}
public get isEmpty(): boolean {
return (
!this.url &&
!this.path &&
!this.valueName &&
!this.titleName &&
!this.imageLinkName
);
return !this.url && !this.path;
}
public getCustomPropertiesNames(): Array<string> {
var properties = this.getCustomProperties();
Expand Down
5 changes: 1 addition & 4 deletions src/question_baseselect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ export class QuestionSelectBase extends Question {
private get waitingChoicesByURL(): boolean {
return !this.isChoicesLoaded && !this.choicesByUrl.isEmpty;
}
private get waitingAcyncOperations(): boolean {
return this.waitingChoicesByURL || this.waitingGetChoiceDisplayValueResponse;
}
@property({ onSet: (newVal: any, target: QuestionSelectBase) => {
target.onSelectedItemValuesChangedHandler(newVal);
} }) protected selectedItemValues: any;
Expand Down Expand Up @@ -581,7 +578,7 @@ export class QuestionSelectBase extends Question {
const value = this.value;
const valueArray: Array<any> = Array.isArray(value) ? value : [value];
const hasItemWithoutValues = valueArray.some(val => !ItemValue.getItemByValue(this.choices, val));
if (hasItemWithoutValues) {
if (hasItemWithoutValues && (this.choicesLazyLoadEnabled || !this.choicesByUrl.isEmpty)) {
this.waitingGetChoiceDisplayValueResponse = true;
this.updateIsReady();
this.survey.getChoiceDisplayValue({
Expand Down
6 changes: 1 addition & 5 deletions tests/questionDropdownTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1633,7 +1633,7 @@ QUnit.test("isReady flag + onGetChoiceDisplayValue", assert => {
log += `->onReadyChanged: ${opt.isReady}`;
if(opt.isReady) {
assert.ok(question.isReady);
assert.notOk(question["waitingAcyncOperations"]);
assert.ok(question.isReady);
assert.notOk(question["waitingChoicesByURL"]);
assert.notOk(question["waitingGetChoiceDisplayValueResponse"]);
assert.equal(log, "->onReadyChanged: false->onGetChoiceDisplayValue->onReadyChanged: true");
Expand All @@ -1643,7 +1643,6 @@ QUnit.test("isReady flag + onGetChoiceDisplayValue", assert => {
});
survey.data = { "q1": "ford" };
assert.notOk(question.isReady);
assert.ok(question["waitingAcyncOperations"]);
assert.notOk(question["waitingChoicesByURL"]);
assert.ok(question["waitingGetChoiceDisplayValueResponse"]);
});
Expand Down Expand Up @@ -1671,7 +1670,6 @@ QUnit.test("isReady flag + onGetChoiceDisplayValue + choicesRestfull", assert =>
log += `->onReadyChanged: ${opt.isReady}`;
if(opt.isReady) {
assert.ok(question.isReady);
assert.notOk(question["waitingAcyncOperations"]);
assert.notOk(question["waitingChoicesByURL"]);
assert.notOk(question["waitingGetChoiceDisplayValueResponse"]);
assert.equal(log, "->onReadyChanged: false->onGetChoiceDisplayValue->onReadyChanged: true");
Expand All @@ -1681,12 +1679,10 @@ QUnit.test("isReady flag + onGetChoiceDisplayValue + choicesRestfull", assert =>
question.choicesByUrl.url = "some url";
survey.data = { "q1": "ford" };
assert.notOk(question.isReady);
assert.ok(question["waitingAcyncOperations"]);
assert.ok(question["waitingChoicesByURL"]);
assert.ok(question["waitingGetChoiceDisplayValueResponse"]);
question.choicesLoaded();
assert.notOk(question.isReady);
assert.ok(question["waitingAcyncOperations"]);
assert.notOk(question["waitingChoicesByURL"]);
assert.ok(question["waitingGetChoiceDisplayValueResponse"]);
});
Expand Down
44 changes: 44 additions & 0 deletions tests/surveyquestiontests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7370,3 +7370,47 @@ QUnit.test("question.isReady & async functions in conditions, visibleIf&enabledI
FunctionFactory.Instance.unregister("asyncFunc1");
FunctionFactory.Instance.unregister("asyncFunc2");
});

QUnit.test("Test", function (assert) {
const survey = new SurveyModel({
pages: [
{
name: "page1",
elements: [
{
type: "text",
name: "q1",
},
{
type: "dropdown",
name: "q2",
showCommentArea: true
},
],
},
],
});
const q2 = survey.getQuestionByName("q2");
assert.equal(q2.choicesByUrl.isEmpty, true, "choicesByUrl.isEmpty");
assert.equal(q2.choicesByUrl.url, "", "choicesByUrl.url");
assert.equal(q2.choicesByUrl.path, "", "choicesByUrl.path");
let counter = 0;
q2.onReadyChanged.add((sender, options) => {
counter ++;
});
const data1 = {
q1: "q1_value",
q2: "q2_value",
};
survey.data = data1;
assert.deepEqual(survey.data, data1, "#1");
assert.equal(counter, 0, "#1");
const data2 = {
q1: "q1_value",
q2: "q2_value",
"q2-Comment": "r32r2r23r23r",
};
survey.data = data2;
assert.deepEqual(survey.data, data2, "#2");
assert.equal(counter, 0, "#2");
});

0 comments on commit 6181130

Please sign in to comment.