Notice
You should replace your model JSON file with these example codes.
Here we explain the basic model of the project. Data is stored as JSON and synchronized in real-time for every connected client. So we can store data in CloadIO as a JSON file like the below steps:
You should replace your model JSON file with these example codes.
{
"version": 202105120735,
"common": {
"sub": {
"client": {
"text": "Form Title",
"sub": {
"first": {
"text": "First Name"
},
"last": {
"text": "Last Name"
},
"gender": {
"text": "Gender",
"inputType": "select",
"src": "key",
"value": {
"0": {
"text": "Male"
},
"1": {
"text": "Female"
}
}
},
"createdAt": {
"text": "Created At",
"inputType": "time",
"display": "inTable"
},
"createdBy": {
"text": "Created By",
"display": "inTable"
}
}
}
}
}
}
Now, open the dashboard.cloadio.com. After login into project account, open the browser console and enter the following commands. Then press enter.
var model = JSON.parse(`{
"version": 202105120735,
"common": {
"sub": {
"client": {
"text": "Form Title",
"sub": {
"first": {
"text": "First Name"
},
"last": {
"text": "Last Name"
},
"gender": {
"text": "Gender",
"inputType": "select",
"src": "key",
"value": {
"0": {
"text": "Male"
},
"1": {
"text": "Female"
}
}
},
"createdAt": {
"text": "Created At",
"inputType": "time",
"display": "inTable"
},
"createdBy": {
"text": "Created By",
"display": "inTable"
}
}
}
}
}
}`);
ref.child('model').set(model, function (error) {
if (error)
console.log(error);
else
console.log('ok');
});
You can get the data in app.js if you need them on more than one page, else you can get the data on the specific page that is needed.
ref.child('model').get(function (error, values) {
if (error)
console.log(error);
else if (values) {
if (!app.local.model)
app.local.model = {};
app.local.model = values;
}
});
For more details about CloadIO visit the CloadIO website.
The Model file has two general sections. The first is the version for controlling the changes, and the other is object contains fields and their properties.
The version is based on timestamp syntax and it should be 12 digits. When each object, field and etc is modified or added tofile, it should be changed. It is in order to upload the model toCloadIo, so we can have version control and get the new changes.
Consider that according to every change the new version number should be greater than the previous version number.
{
"version": 202105120735
}
The objects section includes all objects, fields, and properties. According todifferent project sections we can define separated objects like the client, dashboard, etc. There is a common object too, for general and common fields and properties.
Parameters | Type | Description |
---|---|---|
text | String | Optional. The title of field. |
required | boolean | Optional. Is this field is required or not? If it is required we write it true. |
inputType | string | Optional. The default of this is a string and it is "text", otherwise, you should write one of the below input types:
|
placeholder | String | Optional. The text for placeholder of the field. |
toolTip | String | Optional. It is a message to more describe the field. |
display | String | Optional. This property is for when we want to show or hide the field in the form or table. It can be "inTable", "inForm" or "none". |
accept | String | Optional. Accepted files type or images are included in this section. |
value | Object | Optional. The field values are here. These are the items of fields. For example, when we have a select input type, it should have value property for have item selecting possibility. |
src | String | Optional. It is a key related to selected item. |
format | String | Optional. This is the time format. |
syntax | String | Optional. This is a sequence of characters or regular expressions that specifies a pattern. |
options | Object | Optional. It is for when we need to add some customization code to form or table. |
We add some examples of the kind of input types here.
{
"version": 202105120735,
"common": {
"sub": {
"client": {
"text": "Form Title",
"sub": {
"first": {
"text": "First Name",
"placeholder": "Please enter your first name.",
"toolTip" : "This is your first name",
"required": true,
"display": "inForm"
},
"last": {
"text": "Last Name",
"placeholder": "Please enter your last name.",
"toolTip" : "This is your last name",
"required": true,
"display": "inForm"
},
"gender": {
"text": "Gender",
"inputType": "select",
"src": "key",
"value": {
0: {
"text": "Male"
},
1: {
"text": "Female"
}
},
"display": "inTable"
},
"email": {
"text": "E-Mail",
"inputType": "email",
"placeholder": "Please enter your email.",
"toolTip" : "This is your email",
"required": true,
"display": "inForm"
},
"location": {
"text": "Location",
"inputType": "map"
},
"birthDate": {
"text": "Birth Date",
"inputType": "time",
"format": "YYYY/MM/DD",
"options": {
"timePicker": {
"enabled": true
}
},
"display": "inTable"
},
"nationalCode": {
"text": "National Code",
"required": true,
"syntax":{
"value":"^\\\\d{10}$",
"message":"Invalid national code field."
}
},
"file": {
"text": "Your photo or video",
"inputType": "file",
"accept": "video/mp4, video/x-m4v, video/*, image/*",
"display": "inForm",
"required": true
},
"createdAt": {
"text": "Created At",
"inputType": "time",
"display": "inTable"
},
"createdBy": {
"text": "Created By",
"display": "none"
}
}
}
}
}
}