-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphone.html
More file actions
72 lines (69 loc) · 2.38 KB
/
phone.html
File metadata and controls
72 lines (69 loc) · 2.38 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
<link rel="import" href="bower_components/polymer/polymer-element.html">
<script src="https://unpkg.com/string-mask@0.3.0/src/string-mask.js"></script>
<dom-module id="ns-phone">
<template>
{{label}} <input type="text" value="{{value::input}}">
</template>
<script>
class NsPhone extends Polymer.Element {
connectedCallback() {
super.connectedCallback();
}
static get is() { return 'ns-phone'}
static get properties() {
return {
country: {
type: String
},
strings: {
type: Object,
value: {
en: {
label: 'Phone'
},
de: {
label: 'Telefon'
},
es: {
label: 'Telefono'
}
}
},
rules: {
type: Object,
value: {
US: {
mask: '(###) ###-####',
maxLength: 10
},
DE: {
mask: '###-####'
}
}
},
label: {
type: String
},
value: {
type:String,
notify: true,
reflectToAttribute: true,
observer: 'formatNumber'
}
}
}
formatNumber(newVal, oldVal) {
var rule = this.rules[this.country];
if (rule) {
var formatter = new StringMask(rule.mask);
if (rule.maxLength && newVal && (newVal.length > rule.maxLength)) {
this.value = oldVal;
}
var formattedValue = formatter.apply(this.value);
console.log("formatted value:"+formattedValue);
}
}
}
customElements.define(NsPhone.is, NsPhone);
</script>
</dom-module>