-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
108 lines (102 loc) · 3.25 KB
/
Copy pathscript.js
File metadata and controls
108 lines (102 loc) · 3.25 KB
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
106
107
108
var app = angular.module('app',
['lumx',
'ngMessages',
'ngAria',
'formly',
'formlyLumx',
'ui.bootstrap'
], function config() {
// set templates here
});
app.run(function(formlyConfig) {
formlyConfig.setType({
name: 'lx-input-custom',
templateUrl: 'custom-template.html'
});
});
app.controller('MainCtrl', function MainCtrl($scope) {
'use strict';
var vm = this;
vm.exampleTitle = 'Login page';
vm.formData = {}; // the data object
vm.formOptions = {}; // optional form parameters
vm.formFields = [{
key: 'email', // {
type: 'lx-input',
wrapper: 'lx-wrapper-errors', // error handling with ngMessages
templateOptions: {
type: 'email', // input type: [email | password | text | url | number]
label: 'Email',
required: true
},
validation: {
messages: {
email: function (viewValue, modelValue, scope) {
return 'That doesn\'t look like a valid email.'
}
}
}
},{
key: 'password',
type: 'lx-input-custom',
wrapper: 'lx-wrapper-errors',
templateOptions: {
type: 'password',
label: 'Password',
minlength: 6,
maxlength: 20,
required: true
},
validators: {
atLeastCharacters: {
expression: function(viewValue, modelValue) {
var value = modelValue || viewValue;
if (!value) return false;
return value.length >= 6 && value.length <= 20;
},
message: '"At least 6 characters and maximum 20 characters"'
},
oneLetter: {
expression: function(viewValue, modelValue) {
var value = modelValue || viewValue;
return /(?=.*[0-9])/.test(value);
},
message: '"Password must contain at least one digit"'
},
oneSpecialCharacter: {
expression: function(viewValue, modelValue) {
var value = modelValue || viewValue;
return /(?=.*[!@#$%^&*])/.test(value);
},
message: '"Password must contain at least one special character"'
},
notAnEmail: {
expression: function(viewValue, modelValue, scope) {
var value = modelValue || viewValue;
if (!scope.model.email) return false;
return !value.includes(scope.model.email);
},
message: '"Password must NOT contain your e-mail"'
},
},
ngModelAttrs: {
minlength: {
bound: 'ng-minlength',
attribute: 'minlength'
},
maxlength: {
bound: 'ng-maxlength',
attribute: 'maxlength'
}
},
modelOptions: {
allowInvalid: true,
updateOn: 'default blur keydown',
debounce: {
keydown: 0,
default: 0,
blur: 0
}
}
}];
});