Skip to content

Commit

Permalink
Fix the bug, koVisibleRateValues doesn't update correctly: surveyjs/s…
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Telnov (DevExpress) authored and Andrew Telnov (DevExpress) committed Oct 8, 2017
1 parent 3a72878 commit a79b898
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
5 changes: 0 additions & 5 deletions src/knockout/koquestion_rating.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ class QuestionRatingImplementor extends QuestionImplementor {
this.koChange = function (val) { self.koValue(val.itemValue); };
this.question["koChange"] = this.koChange;
(<QuestionRating>this.question).rateValuesChangedCallback = function () { self.onRateValuesChanged(); };
(<QuestionRating>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 = (<QuestionRating>self.question).itemCss;
var selected = (<QuestionRating>self.question).selectedCss;
Expand Down
9 changes: 9 additions & 0 deletions src/question_rating.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions tests/ko/survey_kotests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <QuestionRating>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");
Expand Down

0 comments on commit a79b898

Please sign in to comment.