From a79b8988e384d8b7c5d8e31a2cd3b34c417bc319 Mon Sep 17 00:00:00 2001 From: "Andrew Telnov (DevExpress)" Date: Sun, 8 Oct 2017 19:07:22 +0300 Subject: [PATCH] Fix the bug, koVisibleRateValues doesn't update correctly: https://github.com/surveyjs/editor/issues/171 --- src/knockout/koquestion_rating.ts | 5 ----- src/question_rating.ts | 9 +++++++++ tests/ko/survey_kotests.ts | 9 +++++++++ 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/knockout/koquestion_rating.ts b/src/knockout/koquestion_rating.ts index 293147302a..d46c084b6a 100644 --- a/src/knockout/koquestion_rating.ts +++ b/src/knockout/koquestion_rating.ts @@ -15,11 +15,6 @@ class QuestionRatingImplementor extends QuestionImplementor { this.koChange = function (val) { self.koValue(val.itemValue); }; this.question["koChange"] = this.koChange; (this.question).rateValuesChangedCallback = function () { self.onRateValuesChanged(); }; - (this.question).onPropertyChanged.add(function(sender, options){ - if(options.name == "rateMin" || options.name == "rateMax" || options.name == "rateStep") { - self.onRateValuesChanged(); - } - }); this.question["koGetCss"] = function (val) { var css = (self.question).itemCss; var selected = (self.question).selectedCss; diff --git a/src/question_rating.ts b/src/question_rating.ts index 43d5e35c38..9da8e72ec1 100644 --- a/src/question_rating.ts +++ b/src/question_rating.ts @@ -18,12 +18,21 @@ export class QuestionRatingModel extends Question { this.rates = this.createItemValues("rates"); var self = this; this.registerFunctionOnPropertyValueChanged("rates", function() {self.fireCallback(self.rateValuesChangedCallback);}); + this.onPropertyChanged.add(function(sender, options){ + if(options.name == "rateMin" || options.name == "rateMax" || options.name == "rateStep") { + self.fireCallback(self.rateValuesChangedCallback); + } + }); var locMinRateDescriptionValue = this.createLocalizableString("minRateDescription", this, true); var locMaxRateDescriptionValue = this.createLocalizableString("maxRateDescription", this, true); locMinRateDescriptionValue.onGetTextCallback = function(text) { return text ? text + " " : text; } locMaxRateDescriptionValue.onGetTextCallback = function(text) { return text ? " " + text : text; } } + public onSurveyLoad() { + super.onSurveyLoad(); + this.fireCallback(this.rateValuesChangedCallback); + } /** * The list of rate items. Every item has value and text. If text is empty, the value is rendered. The item text supports markdown. If it is empty the array is generated by using rateMin, rateMax and rateStep properties. * @see rateMin diff --git a/tests/ko/survey_kotests.ts b/tests/ko/survey_kotests.ts index 4d677f47bd..91de4679ed 100644 --- a/tests/ko/survey_kotests.ts +++ b/tests/ko/survey_kotests.ts @@ -419,6 +419,15 @@ QUnit.test("PanelDynamic and koRenderedHtml on text processing", function (asser assert.equal(pLocTitle["koRenderedHtml"](), "val1", "np1 title is q1.value"); }); +QUnit.test("Load rating from JSON, bug# https://github.com/surveyjs/editor/issues/171", function (assert) { + var json = { questions: [ {type: "rating", name: "q", rateMax: 8, rateMin : 2, rateStep: 2 }]}; + var survey = new Survey(json); + + var question = survey.getAllQuestions()[0]; + assert.equal(question["koVisibleRateValues"]().length, 4, "There are 4 items: 2, 4, 6, 8"); + +}); + function createPageWithQuestion(name: string): Page { var page = new Page(name); page.addNewQuestion("text", "q1");