Skip to content

Commit

Permalink
Merge pull request #6701 from surveyjs/features/6061-renanme-properties
Browse files Browse the repository at this point in the history
Features/6061 rename properties
  • Loading branch information
andrewtelnov authored Aug 11, 2023
2 parents 23a1ebb + bd2a8dc commit 272f39e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
26 changes: 13 additions & 13 deletions src/question_baseselect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class QuestionSelectBase extends Question {
}
});
this.registerPropertyChangedHandlers(
["choicesFromQuestion", "choicesFromQuestionMode", "choicesFromValueName", "choicesFromTextName", "showNoneItem"],
["choicesFromQuestion", "choicesFromQuestionMode", "choiceValuesFromQuestion", "choiceTextsFromQuestion", "showNoneItem"],
() => {
this.onVisibleChoicesChanged();
}
Expand Down Expand Up @@ -720,17 +720,17 @@ export class QuestionSelectBase extends Question {
public set choicesFromQuestionMode(val: string) {
this.setPropertyValue("choicesFromQuestionMode", val);
}
public get choicesFromValueName(): string {
return this.getPropertyValue("choicesFromValueName");
public get choiceValuesFromQuestion(): string {
return this.getPropertyValue("choiceValuesFromQuestion");
}
public set choicesFromValueName(val: string) {
this.setPropertyValue("choicesFromValueName", val);
public set choiceValuesFromQuestion(val: string) {
this.setPropertyValue("choiceValuesFromQuestion", val);
}
public get choicesFromTextName(): string {
return this.getPropertyValue("choicesFromTextName");
public get choiceTextsFromQuestion(): string {
return this.getPropertyValue("choiceTextsFromQuestion");
}
public set choicesFromTextName(val: string) {
this.setPropertyValue("choicesFromTextName", val);
public set choiceTextsFromQuestion(val: string) {
this.setPropertyValue("choiceTextsFromQuestion", val);
}
/**
* Specifies whether to hide the question if no choice items are visible.
Expand Down Expand Up @@ -1058,14 +1058,14 @@ export class QuestionSelectBase extends Question {
if(!Helpers.isValueObject(obj)) continue;
const key = this.getValueKeyName(obj);
if(!!key && !this.isValueEmpty(obj[key])) {
const text = !!this.choicesFromTextName ? obj[this.choicesFromTextName] : undefined;
const text = !!this.choiceTextsFromQuestion ? obj[this.choiceTextsFromQuestion] : undefined;
res.push(this.createItemValue(obj[key], text));
}
}
return res;
}
private getValueKeyName(obj: any): string {
if(this.choicesFromValueName) return this.choicesFromValueName;
if(this.choiceValuesFromQuestion) return this.choiceValuesFromQuestion;
const keys = Object.keys(obj);
return keys.length > 0 ? keys[0] : undefined;
}
Expand Down Expand Up @@ -1803,14 +1803,14 @@ Serializer.addClass(
},
},
{
name: "choicesFromValueName",
name: "choiceValuesFromQuestion",
dependsOn: "choicesFromQuestion",
visibleIf: (obj: any) => {
return obj.carryForwardQuestionType === "array";
},
},
{
name: "choicesFromTextName",
name: "choiceTextsFromQuestion",
dependsOn: "choicesFromQuestion",
visibleIf: (obj: any) => {
return obj.carryForwardQuestionType === "array";
Expand Down
14 changes: 7 additions & 7 deletions tests/question_baseselecttests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1092,15 +1092,15 @@ QUnit.test("Use carryForward with matrix dynamic", function (assert) {
assert.equal(q2.visibleChoices[2].value, "C", "the third value is correct");
});

QUnit.test("Use carryForward with matrix dynamic + choicesFromValueName", function (assert) {
QUnit.test("Use carryForward with matrix dynamic + choiceValuesFromQuestion", function (assert) {
const survey = new SurveyModel({ elements: [
{ type: "matrixdynamic", name: "q1", columns: [{ name: "col1", cellType: "text" }, { name: "col2", cellType: "text" }] },
{ type: "checkbox", name: "q2", choicesFromQuestion: "q1", choicesFromValueName: "col2" }
{ type: "checkbox", name: "q2", choicesFromQuestion: "q1", choiceValuesFromQuestion: "col2" }
] });
const q1 = <QuestionMatrixDynamicModel>survey.getQuestionByName("q1");
const q2 = <QuestionSelectBase>survey.getQuestionByName("q2");
assert.equal(q2.choicesFromQuestion, "q1", "choicesFromQuestion is set");
assert.equal(q2.choicesFromValueName, "col2", "choicesFromValueName is set");
assert.equal(q2.choiceValuesFromQuestion, "col2", "choiceValuesFromQuestion is set");
assert.equal(q2.isUsingCarryForward, true, "Carryforward flag is set");
assert.equal(q2.visibleChoices.length, 0, "There is no choices");
assert.equal(q2.visibleChoices.length, 0, "There is no choices, row is empty");
Expand All @@ -1121,18 +1121,18 @@ QUnit.test("Use carryForward with matrix dynamic + choicesFromValueName", functi
assert.equal(q2.visibleChoices.length, 3, "There are three choice");
assert.equal(q2.visibleChoices[2].value, "CC", "the third value is correct");
});
QUnit.test("Use carryForward with panel dynamic + choicesFromValueName&choicesFromTextName", function (assert) {
QUnit.test("Use carryForward with panel dynamic + choiceValuesFromQuestion&choiceTextsFromQuestion", function (assert) {
const survey = new SurveyModel({ elements: [
{ type: "paneldynamic", name: "q1", panelCount: 2,
templateElements: [{ name: "q1-q1", type: "text" }, { name: "q1-q2", type: "text" }, { name: "q1-q3", type: "text" }]
},
{ type: "checkbox", name: "q2", choicesFromQuestion: "q1", choicesFromValueName: "q1-q2", choicesFromTextName: "q1-q3" }
{ type: "checkbox", name: "q2", choicesFromQuestion: "q1", choiceValuesFromQuestion: "q1-q2", choiceTextsFromQuestion: "q1-q3" }
] });
const q1 = <QuestionPanelDynamicModel>survey.getQuestionByName("q1");
const q2 = <QuestionSelectBase>survey.getQuestionByName("q2");
assert.equal(q2.choicesFromQuestion, "q1", "choicesFromQuestion is set");
assert.equal(q2.choicesFromValueName, "q1-q2", "choicesFromValueName is set");
assert.equal(q2.choicesFromTextName, "q1-q3", "choicesFromTextName is set");
assert.equal(q2.choiceValuesFromQuestion, "q1-q2", "choiceValuesFromQuestion is set");
assert.equal(q2.choiceTextsFromQuestion, "q1-q3", "choiceTextsFromQuestion is set");
assert.equal(q2.isUsingCarryForward, true, "Carryforward flag is set");
assert.equal(q2.visibleChoices.length, 0, "There is no choices");
q1.panels[0].getQuestionByName("q1-q1").value = "A";
Expand Down

0 comments on commit 272f39e

Please sign in to comment.