Skip to content

Commit

Permalink
Descriptions of a composite component's fields appear duplicated in t…
Browse files Browse the repository at this point in the history
…he Translation tab fix #8238 (#8239)
  • Loading branch information
andrewtelnov authored May 6, 2024
1 parent 5ff94d0 commit 44e658c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/jsonobject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1160,9 +1160,17 @@ export class JsonMetadata {
return metaClass.getAllProperties();
}
public getPropertiesByObj(obj: any): Array<JsonObjectProperty> {
if (!obj || !obj.getType) return [];
const props = this.getProperties(obj.getType());
const type = !!obj && !!obj.getType ? obj.getType() : undefined;
if (!type) return [];
const props = this.getProperties(type);
const dynamicProps = this.getDynamicPropertiesByObj(obj);
for(let i = dynamicProps.length -1; i >= 0; i --) {
if(this.findProperty(type, dynamicProps[i].name)) {
dynamicProps.splice(i, 1);
}
}
if(dynamicProps.length === 0) return props;

return [].concat(props).concat(dynamicProps);
}
public addDynamicPropertiesIntoObj(dest: any, src: any, props: Array<JsonObjectProperty>): void {
Expand Down
33 changes: 33 additions & 0 deletions tests/question_customtests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3237,3 +3237,36 @@ QUnit.test("Single: use incorrect json", function (assert) {
ComponentCollection.Instance.clear();
ConsoleWarnings.error = prev;
});
QUnit.test("single component: inheritBaseProps - do not duplicate description property", function (assert) {
ComponentCollection.Instance.add({
name: "customdropdown",
inheritBaseProps: ["description"],
questionJSON: {
type: "dropdown",
description: {
en: "Custom Question",
de: "Aangepaste vraag"
},
choices: [1, 2, 3]
},
});

const survey = new SurveyModel({
elements: [
{ type: "customdropdown", name: "q1" }
]
});
const q1 = <QuestionCustomModel>survey.getQuestionByName("q1");
assert.equal(q1.description, "Custom Question", "Get description from internal description");
survey.locale = "de";
assert.equal(q1.description, "Aangepaste vraag", "Get description from internal description for 'de'");
const props = Serializer.getPropertiesByObj(q1);
let descriptionCounter = 0;
props.forEach(prop => {
if(prop.name === "description") {
descriptionCounter ++;
}
});
assert.equal(descriptionCounter, 1, "We have one description property");
ComponentCollection.Instance.clear();
});

0 comments on commit 44e658c

Please sign in to comment.