-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathDemoForm.js
105 lines (101 loc) · 3.53 KB
/
DemoForm.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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
const el = redom.el;
class DemoForm {
constructor() {
this.username = '';
this.password = '';
this.el = el(
'form',
{ id: 'loginForm', method: 'POST' },
el(
'div',
{ className: 'form-group row' },
el('label', { className: 'col-sm-3 col-form-label' }, 'Username'),
el(
'div',
{ className: 'col-sm-4' },
el('input', {
className: 'form-control',
type: 'text',
name: 'username',
oninput: (e) => (this.username = e.target.value),
})
)
),
el(
'div',
{ className: 'form-group row' },
el('label', { className: 'col-sm-3 col-form-label' }, 'Password'),
el(
'div',
{ className: 'col-sm-4' },
el('input', {
className: 'form-control',
type: 'password',
name: 'password',
oninput: (e) => (this.password = e.target.value),
})
)
),
el(
'div',
{ className: 'form-group row' },
el(
'div',
{ className: 'col-sm-9 offset-sm-3' },
el('button', { className: 'btn btn-primary', type: 'submit' }, 'Login')
)
)
);
}
onmount() {
const that = this;
this.fv = FormValidation.formValidation(document.getElementById('loginForm'), {
fields: {
username: {
validators: {
notEmpty: {
message: 'The username is required',
},
stringLength: {
min: 6,
max: 30,
message: 'The username must be more than 6 and less than 30 characters long',
},
regexp: {
regexp: /^[a-zA-Z0-9_]+$/,
message: 'The username can only consist of alphabetical, number and underscore',
},
},
},
password: {
validators: {
notEmpty: {
message: 'The password is required',
},
stringLength: {
min: 8,
message: 'The password must have at least 8 characters',
},
},
},
},
plugins: {
trigger: new FormValidation.plugins.Trigger(),
submitButton: new FormValidation.plugins.SubmitButton(),
bootstrap: new FormValidation.plugins.Bootstrap(),
icon: new FormValidation.plugins.Icon({
valid: 'fa fa-check',
invalid: 'fa fa-times',
validating: 'fa fa-refresh',
}),
},
}).on('core.form.valid', () => {
console.log(this.username, this.password);
});
}
onunmount() {
if (this.fv) {
this.fv.destroy();
}
}
}