Skip to content

Commit

Permalink
Parse survey json in the survey constructor, if it is a string:
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtelnov committed Jul 13, 2017
1 parent fafab7f commit 7407faa
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
3 changes: 3 additions & 0 deletions src/survey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,9 @@ export class SurveyModel extends Base implements ISurvey, ISurveyTriggerOwner, I
this.updateProcessedTextValues();
this.onBeforeCreating();
if (jsonObj) {
if (typeof jsonObj === 'string' || jsonObj instanceof String) {
jsonObj = JSON.parse(jsonObj as string);
}
this.setJsonObject(jsonObj);
if (this.surveyId) {
this.loadSurveyFromService(this.surveyId);
Expand Down
30 changes: 15 additions & 15 deletions tests/lowercasetests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,31 +62,31 @@ QUnit.test("MultipleTextItemModel inputType value is always lower-case", functio
});

QUnit.test("SurveyModel showQuestionNumbers value is always lower-case", function (assert) {
var question = new SurveyModel("text");
question.showQuestionNumbers = "OFF";
assert.strictEqual(question.showQuestionNumbers, "off");
var survey = new SurveyModel();
survey.showQuestionNumbers = "OFF";
assert.strictEqual(survey.showQuestionNumbers, "off");
});

QUnit.test("SurveyModel showQuestionNumbers value handles onPage special case", function (assert) {
var question = new SurveyModel("text");
question.showQuestionNumbers = "ONPAGE";
assert.strictEqual(question.showQuestionNumbers, "onPage");
var survey = new SurveyModel();
survey.showQuestionNumbers = "ONPAGE";
assert.strictEqual(survey.showQuestionNumbers, "onPage");
});

QUnit.test("SurveyModel questionTitleLocation value is always lower-case", function (assert) {
var question = new SurveyModel("text");
question.questionTitleLocation = "BOTTOM";
assert.strictEqual(question.questionTitleLocation, "bottom");
var survey = new SurveyModel();
survey.questionTitleLocation = "BOTTOM";
assert.strictEqual(survey.questionTitleLocation, "bottom");
});

QUnit.test("SurveyModel showProgressBar value is always lower-case", function (assert) {
var question = new SurveyModel("text");
question.showProgressBar = "TOP";
assert.strictEqual(question.showProgressBar, "top");
var survey = new SurveyModel();
survey.showProgressBar = "TOP";
assert.strictEqual(survey.showProgressBar, "top");
});

QUnit.test("SurveyModel mode value is always lower-case", function (assert) {
var question = new SurveyModel("text");
question.mode = "DISPLAY";
assert.strictEqual(question.mode, "display");
var survey = new SurveyModel();
survey.mode = "DISPLAY";
assert.strictEqual(survey.mode, "display");
});
6 changes: 6 additions & 0 deletions tests/surveytests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1480,3 +1480,9 @@ QUnit.test("Pass custom properties to cell question", function (assert) {
assert.equal(q1.visibleRows[0].cells[0].question['renderAs'], "select2tagbox", "custom property should be passed to the question");
});

QUnit.test("Pass text as survey json", function (assert) {
var survey = new SurveyModel('{ "questions": [ {"type": "text", "name": "q1"}]}');
var q1 = survey.getQuestionByName("q1");
assert.equal(q1.name, "q1", "The survey created from the string");
});

0 comments on commit 7407faa

Please sign in to comment.