Add properties
Add a new property to any object
Survey.Survey.cssType = "bootstrap";
Survey.defaultBootstrapCss.navigationButton = "btn btn-green";
//add a property to the survey object
Survey.JsonObject.metaData.addProperty("survey", "tag:number");
//add a property to the page object
Survey.JsonObject.metaData.addProperty("page", {name: "tag:number", default: 1});
//add a property to the base question class and as result to all questions 
Survey.JsonObject.metaData.addProperty("questionbase", {name: "tag:number", default: 0});
var editorOptions = { };
var editor = new SurveyEditor.SurveyEditor("editorElement", editorOptions);

<!DOCTYPE html>
<html>
<head>
    <title>Add a new property to any object, SurveyJS Editor Example</title>
    <script src="https://unpkg.com/jquery"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.3.0/knockout-min.js"></script>
    <script src="https://surveyjs.azureedge.net/0.12.34/survey.ko.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.0/ace.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.0/worker-json.js" type="text/javascript" charset="utf-8"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.0/mode-json.js" type="text/javascript" charset="utf-8"></script>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js"></script>
    <link href="https://surveyjs.azureedge.net/0.12.34/surveyeditor.css" type="text/css" rel="stylesheet" />
    <script src="https://surveyjs.azureedge.net/0.12.34/surveyeditor.js"></script>
    <link rel="stylesheet" href="https://unpkg.com/bootstrap@3.3.7/dist/css/bootstrap.min.css">
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="./index.css">

</head>
<body>
    <div id="surveyContainer">
    <div id="editorElement"></div>
</div>

<script type="text/javascript" src="./index.js"></script>

</body>
</html>
.btn-green {
  background-color: #1ab394;
  color: #fff;
  border-radius: 3px;
}
.btn-green:hover, .btn-green:focus {
    background-color: #18a689;
    color: #fff;
}
.panel-footer {
    padding: 0 15px;
    border:none;
    text-align: right;
    background-color: #fff;
}

Property definition specification

Short definition

"propertyName[:propertyType]"

Full definition

{name: "propertyName[:propertyType]" [, default: defaultValue][, choices: Array of values]
[, onGetValue: function (obj) { return yourValueFromObject; }]
[, onSetValue: function (obj: any, value: any) {/*perform an action on setting value */ }]}

propertyName

A property name. If a property name begins with �!�, it means the property is required. If the property is not set, the json parser will raise an error. For example, "name" and "type" properties of the question object are required: "!type" � it means that string property "type" is required.

propertyType

It is an optional attribute. If the value is not set then the library treats it as a string property.
  • string � it is the default value type. Property editor is a text input. "myProperty" and "myProperty:string" - give the same result.
  • boolean � a Boolean type. Property editor is a checkbox.
  • number � a numeric type. Property editor is a text input.
  • text � string type. Property editor is text input with an optional modal window for entering large text.
  • html � string type. Property editor is text input with an optional modal window for entering large text. In the future modal window becomes a very simple html editor.
  • Itemvalues � the array of ItemValue object. ItemValue object has two properties {value: any, text: string}. Dropdown, checkbox and radiogroup questions has choices property with itemvalues type.
  • matrixdropdowncolumns �for matrixdropdown and matrixdynamic columns have this type.
  • texitems � items property of multiple text question has this type
  • triggers � survey triggers property has this type.
  • validators � question validators property has this type.
You are able to introduce your own type and register a new property editor for this new type.

default

It is an optional attribute. The library do not serialize the default value into JSON. By default, the empty text is default for string value, 0 is for numeric and false for boolean. You may change it by using this attribute.
{ name: "mode", default: "edit"}
{ name: "showTitle:boolean", default: true }

choices

It is an optional attribute. It makes sense for string and numeric property types only. If the choices attribute is set, the property editor for the property becomes dropdown. You may assign the array of values to this attribute or a function that will return the array of strings or numbers.
{ name: "showProgressBar", default: "off", choices: ["off", "top", "bottom"] }
//returns the supported languages in the surveyjs library.
{ name: "locale", choices: function() { return Survey.surveyLocalization.getLocales(); } }

onGetValue

It is an optional attribute. You may assign a function to return a value different from the property value.
// get title property returns a title with question number and so on "5) My super title.", 
//but we want to serialize only a "pure" question title "My super title".
{ name: "title:text", onGetValue: function (obj: any) { return obj.titleValue; } }
// the function always returns null. It means that the library will never serialize the property in JSON.
{ name: "calcProperty", onGetValue: function (obj: any) { return null; } }

onSetValue

It is an optional attribute. You may assign a function to set a different object property and/or perform some actions.

{ name: "myValue", onSetValue: function (obj, value, jsonConverter) {obj.myValue = value; /* Perform some actions */ }}