-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalue-password.html
177 lines (119 loc) · 5.23 KB
/
value-password.html
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<!--
@license
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<link rel="import" href="../polymer/polymer.html">
<!--
Print the warn message if the value does not in the given Range
Example:
<value-password max-value="100" message="Value to high">
<input type="text" value="10000" />
</value-password>
@demo
-->
<dom-module id="value-fill">
<style>
:host {
}
</style>
<template>
<content></content>
</template>
</dom-module>
<script>
Polymer({
is: 'value-password',
properties: {
referenceId: String,
messageOk: String,
messageError: String
},
// Element Lifecycle
ready: function() {
},
attached: function() {
var these = this;
these.inputElement = Polymer.dom(these).querySelector('input');
// Array with different Regex Tests all positive
these.regexTests = [];
//Mindestens eine Zahl
these.regexTests.push( { regex: /\d/, name: "number" } );
//Mindestens eine Kleinbuchstabe
these.regexTests.push( { regex: /[a-z]/, name: "small" } );
//Mindestens ein Großbuchstabe
these.regexTests.push( { regex: /[A-Z]/, name: "capital" } );
//Keine dieser Zeichen enthalten
these.regexNegative = /[\s`´]/;
if ( these.inputElement) {
setInterval(function() { these.changeValue() }, 200);
// Prepare warning
these.warn_node = document.createElement('span');
these.warn_node.className = 'error';
these.warn_node.innerHTML = these.messageError;
these.ok_node = document.createElement('span');
these.ok_node.className = 'success';
these.ok_node.innerHTML = these.messageOk;
these.ok_node.style.color = "#519951";
these.ok_node.style.display = "block";
these.passwordOk = true;
// Check initial value!
these.changeValue();
}
},
detached: function() {
},
// Value changed, check!
changeValue: function() {
var these = this;
if( these.inputElement.value !== 'notsetnotset' ) {
if( these.inputElement.value.length < 9 || these.inputElement.value.length > 30 ) {
these.warn_node.innerHTML = 'Mindestens 9, maximal 30 Zeichen';
Polymer.dom(these).appendChild(these.warn_node);
if ( Polymer.dom(these).querySelector('span.success') ) {
Polymer.dom(these).removeChild(these.ok_node);
}
} else {
these.passwordOk = true;
these.regexTests.forEach(
function(element) {
if(element.regex.test(these.inputElement.value) === false) {
these.passwordOk = false;
}
}
);
if( these.regexNegative.test(these.inputElement.value) === true ) {
these.warn_node.innerHTML = "Leerzeichen oder Akzentzeichen sind nicht erlaubt";
Polymer.dom(these).appendChild(these.warn_node);
if ( Polymer.dom(these).querySelector('span.success') ) {
Polymer.dom(these).removeChild(these.ok_node);
}
} else if (these.passwordOk === false) {
these.warn_node.innerHTML = these.messageError;
Polymer.dom(these).appendChild(these.warn_node);
if ( Polymer.dom(these).querySelector('span.success') ) {
Polymer.dom(these).removeChild(these.ok_node);
}
} else {
these.warn_node.innerHTML = these.messageError;
Polymer.dom(these).appendChild(these.ok_node);
if ( Polymer.dom(these).querySelector('span.error') ) {
Polymer.dom(these).removeChild(these.warn_node);
}
}
}
} else {
if ( Polymer.dom(these).querySelector('span.error') ) {
Polymer.dom(these).removeChild(these.warn_node);
}
if ( Polymer.dom(these).querySelector('span.success') ) {
Polymer.dom(these).removeChild(these.ok_node);
}
}
}
});
</script>