Skip to content

Commit

Permalink
Fix the bug with drawing ItemValue if value equals 0: surveyjs#538
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtelnov committed Aug 3, 2017
1 parent cd50e77 commit 6a4d903
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/itemvalue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ export class ItemValue {
items[i].locText.onChanged();
}
}
private static itemValueProp = [ "text", "value", "hasText", "locOwner", "locText"];
private static itemValueProp = [ "text", "value", "hasText", "locOwner", "locText", "isValueEmpty"];
private itemValue: any;
private locTextValue: LocalizableString;
constructor(value: any, text: string = null) {
this.locTextValue = new LocalizableString(null, true);
var self = this;
this.locTextValue.onGetTextCallback = function(text) { return text ? text : (self.value ? self.value.toString() : null); }
this.locTextValue.onGetTextCallback = function(text) { return text ? text : (!self.isValueEmpty ? self.value.toString() : null); }
if(text) this.locText.text = text;
this.value = value;
}
Expand Down Expand Up @@ -106,7 +106,8 @@ export class ItemValue {
this.value = value;
}
}
private isObjItemValue(obj: any) { return typeof (obj.getType) !== 'undefined' && obj.getType() == 'itemvalue'}
private get isValueEmpty() { return !this.itemValue && this.itemValue !== 0 && this.itemValue !== false; }
private isObjItemValue(obj: any) { return typeof (obj.getType) !== 'undefined' && obj.getType() == 'itemvalue';}
private copyAttributes(src: any, exceptons: Array<string>) {
for (var key in src) {
if ((typeof src[key] == 'function')) continue;
Expand Down
7 changes: 7 additions & 0 deletions tests/localizablestringtests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ QUnit.test("Array<ItemValue> localization", function (assert) {
items[0].locText.setLocaleText("", null);
assert.equal(items[0].text, "val1", "Check6, use value");
});
QUnit.test("ItemValue.value = 0, #538", function (assert) {
var owner = new LocalizableOwnerTester("");
var items = ItemValue.createArray(owner);

items.push(new ItemValue(0));
assert.equal(items[0].locText.textOrHtml, "0", "value 0, text should be '0'")
});

QUnit.test("Array<ItemValue> localization serialize", function (assert) {
var owner = new LocalizableOwnerTester("");
Expand Down
15 changes: 15 additions & 0 deletions tests/surveypaneldynamictests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,18 @@ QUnit.test("PanelDynamic in design time", function (assert) {
assert.equal(question.panels.length, 1, "Only one panel at design time");
assert.equal(question.panels[0].id, question.template.id, "The template panel should be shown");
});

/* Think about this-
QUnit.test("PanelDynamic survey.getPageByQuestion/Element", function (assert) {
var survey = new SurveyModel();
survey.setDesignMode(true);
survey.addNewPage("p");
var question = new QuestionPanelDynamicModel("q");
survey.pages[0].addQuestion(question);
question.template.addNewQuestion("text", "q1");
question.template.addNewQuestion("text", "q2");
question.panelCount = 2;
assert.equal(survey.getPageByQuestion(question.template.questions[0]).name, "p", "Template question page is found");
assert.equal(survey.getPageByQuestion(question.panels[0].questions[0]).name, "p", "Nested question page is found");
});
*/
1 change: 0 additions & 1 deletion tests/surveyquestiontests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,6 @@ QUnit.test("Matrixdynamic column.visibleIf, load from json and add item", functi
assert.equal(q_1_1.visible, false, "Initial the question in the added row is invisible");
});


QUnit.test("Text inputType=number", function (assert) {
var question = new QuestionTextModel("text");
question.inputType = "number";
Expand Down

0 comments on commit 6a4d903

Please sign in to comment.