diff --git a/packages/survey-core/src/question_rating.ts b/packages/survey-core/src/question_rating.ts index a8a11e508c..11b0c0dc39 100644 --- a/packages/survey-core/src/question_rating.ts +++ b/packages/survey-core/src/question_rating.ts @@ -365,6 +365,7 @@ export class QuestionRatingModel extends Question { } if (this.rateType == "smileys" && rateValues.length > 10) rateValues = rateValues.slice(0, 10); + this.visibleChoicesValue = rateValues.map((i, idx) => this.getRatingItemValue(i, idx)); this.renderedRateItems = rateValues.map((v, i) => { let renderedItem = null; if (this.displayRateDescriptionsAsExtremeItems) { @@ -383,15 +384,8 @@ export class QuestionRatingModel extends Question { var step = this.rateStep; while (value <= this.rateMax && res.length < settings.ratingMaximumRateValueCount) { - let description: LocalizableString; - if (value === this.rateMin) { - description = this.minRateDescription && this.locMinRateDescription; - } - if (value === this.rateMax || res.length === settings.ratingMaximumRateValueCount) { - description = this.maxRateDescription && this.locMaxRateDescription; - } - let item = new RatingItemValue(value, description); + let item = new ItemValue(value); item.locOwner = this; item.ownerPropertyName = "rateValues"; res.push(item); @@ -399,6 +393,21 @@ export class QuestionRatingModel extends Question { } return res; } + private getRatingItemValue(item, index) { + if (!item) return null; + const value = item.value; + let description: LocalizableString; + if (value === this.rateMin) { + description = this.minRateDescription && this.locMinRateDescription; + } + if (value === this.rateMax || index === settings.ratingMaximumRateValueCount) { + description = this.maxRateDescription && this.locMaxRateDescription; + } + let newItem = new RatingItemValue(value, description); + newItem.locOwner = item.locOwner; + newItem.ownerPropertyName = item.ownerPropertyName; + return newItem; + } private correctValue(value: number, step: number): number { if (!value) return value; @@ -835,8 +844,9 @@ export class QuestionRatingModel extends Question { public isItemSelected(item: ItemValue): boolean { return item.value == this.value; } + private visibleChoicesValue: ItemValue[]; public get visibleChoices(): ItemValue[] { - return this.visibleRateValues; + return this.visibleChoicesValue; } public get readOnlyText() { if (this.readOnly) return (this.displayValue || this.placeholder); diff --git a/tests/markup/etalon_rating.ts b/tests/markup/etalon_rating.ts index 32987145df..10c4fa8cb0 100644 --- a/tests/markup/etalon_rating.ts +++ b/tests/markup/etalon_rating.ts @@ -104,6 +104,37 @@ registerMarkupTests( after: () => StylesManager.applyTheme("default"), snapshot: "rating-as-dropdown", }, + { + name: "Test Rating question as dropdown with description", + json: { + questions: [ + { + name: "name", + type: "rating", + title: "Question title", + titleLocation: "hidden", + minRateDescription: "mimimi", + maxRateDescription: "mamama", + displayMode: "dropdown", + rateValues: [ + 1, + 2, + 3, + 4 + ] + } + ] + }, + initSurvey: (survey) => { + let q1 = survey.getQuestionByName("name"); + const dropdownListModel = new DropdownListModel(q1); + q1["dropdownListModel"] = dropdownListModel; + dropdownListModel["popupModel"].isVisible = true; + }, + before: () => StylesManager.applyTheme("defaultV2"), + after: () => StylesManager.applyTheme("default"), + snapshot: "rating-as-dropdown-description", + }, { name: "Test Rating question as dropdown readonly", json: { diff --git a/tests/markup/snapshots/rating-as-dropdown-description.snap.html b/tests/markup/snapshots/rating-as-dropdown-description.snap.html new file mode 100644 index 0000000000..cd819c93e3 --- /dev/null +++ b/tests/markup/snapshots/rating-as-dropdown-description.snap.html @@ -0,0 +1,65 @@ +
+
+
+
+ +
+
+
+
+
+
+
+
+
+ +
    +
  • +
    +
    + 1 +
    + mimimi +
    +
    +
    +
  • +
  • +
    +
    + 2 +
    +
    +
  • +
  • +
    +
    + 3 +
    +
    +
  • +
  • +
    +
    + 4 +
    +
    +
  • +
+
+
+
+
+
+
+
+ +
+
\ No newline at end of file