forked from johannesjo/generator-angular-auto-admin-loopback
-
Notifications
You must be signed in to change notification settings - Fork 0
/
formly-converter.js
49 lines (38 loc) · 1.14 KB
/
formly-converter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
var helper = require('./helper');
var fs = require('fs');
function convertModelToFormly(model) {
var formlyFields = [];
for (var key in model.properties) {
var field = model.properties[key];
var tplOpts = {};
var formlyField = {
templateOptions: tplOpts
};
formlyField.key = key;
// types
if (field.formlyType) {
formlyField.type = field.formlyType;
}
else if (field.type === 'string' || field.type === 'number') {
formlyField.type = 'input';
}
else if (field.type === 'date') {
//formlyField.type = 'input';
formlyField.type = 'datepicker';
tplOpts.datepickerPopup = 'dd-MMMM-yyyy';
tplOpts.type = 'date';
tplOpts.datepickerOptions = {};
}
// tpl opts
if (field.formlyOpts) {
tplOpts = field.formlyOpts;
}
tplOpts.label = key;
if (field.required) {
tplOpts.required = true;
}
formlyFields.push(formlyField);
}
return formlyFields;
}
module.exports = convertModelToFormly;