-
Notifications
You must be signed in to change notification settings - Fork 0
/
form.ts
86 lines (74 loc) · 2.42 KB
/
form.ts
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
/// <reference path="./client/bower_components/forms-js/dist/forms-js.d.ts" />
*/
import {Component, Template} from 'annotations';
import {bootstrap, Foreach} from 'angular2/angular2';
import {bind} from 'angular2/di';
// import {Form} from 'client/bower_components/forms-js/source/form'
@Component({
selector: 'forms-js-form',
componentServices: [],
bind: {
'thing': 'thing'
}
})
@Template({
url: 'form.html',
directives: [Foreach]
})
export class FormsJsForm {
// formsjs stuff
// formsjsForm: Form;
formsjsForm: any;
// stuff that I was expecting to see in formsjs but can't find
viewSchema: any;
mergedSchema: Array<any>;
// stuff I am messing with
recordjson: any;
thing: any;
formFields: Array<any>;
constructor() {
console.log(this.thing); // Looks like binding doesn't work in this version of ng2, which isn't a problem at the moment
// It works in later betas, but I cabn't get TypeScript to work with those....
// this.formsjsForm = new formsjs.Form();
this.formsjsForm = {};
// Let's hard code a simple example for now, since I can't get the binding to work
this.formsjsForm.formData = {};
this.formsjsForm.validationSchema = {
email: {
key_: 'email',
required: true,
/*pattern: {
value: /.+@.+\..+/,
failureMessage: "%s is not a valid email format"
}*/
pattern: /.+@.+\..+/
} ,
username: {
key_: 'username',
required: true,
min: 6,
pattern: /[0-9a-zA-Z]+/
},
comment: {
key_: 'comment'
}
};
this.viewSchema = {
fields: [
{key: 'username', inputType: 'text', label: 'Username' },
{key: 'email', inputType: 'text', label: 'Email' },
{key: 'comment', inputType: 'textarea', label: 'Comment' }
]
};
this.formFields = this.viewSchema.fields;
this.recordjson = '';
}
setfield(event, field, value) {
this.formsjsForm.formData[field] = value;
this.recordjson = JSON.stringify(this.formsjsForm.formData, null, 2)
}
}
export function main() {
bootstrap(FormsJsForm);
}