-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapril_rel_2020_v5.js
More file actions
237 lines (212 loc) · 6.88 KB
/
Copy pathapril_rel_2020_v5.js
File metadata and controls
237 lines (212 loc) · 6.88 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
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
(function($){
window.addEventListener('load', function(){
formatFields();
//return returnHiddenValue(); //for testing only hiddenValue
});
var dataId_phone = '51523791';
var dataId_website = '51523815';
var dataId_eOLiabilityLimits = '51523817';
var dataId_eoLimitsHolder = '51523818';
var keyPressVal;
var dataId_yearEstablished = 51523814; //prod 47134549
var dataId_duplicateMessage = '51523788';
// for Search form
var dataId_email = '51523792';
var dataId_hiddenReturnedAccount = 51523789;
var dataId_checker = 62227210;
function formatPhone(){
$("div[data-id='"+dataId_phone+"']").find("input")
.on('keypress', function(e) {
var key = e.charCode || e.keyCode || 0;
var phone = $(this);
if (phone.val().length === 0) {
phone.val(phone.val() + '(');
} else {
var val = phone.val();
phone.val('').val(val);
}
if(phone.val() === '('){
keyPressVal = phone.val();
} else {
keyPressVal = '';
}
// Auto-format- do not expose the mask as the user begins to type
if (key !== 8 && key !== 9) {
if (phone.val().length === 4) {
phone.val(phone.val() + ')');
}
if (phone.val().length === 5) {
phone.val(phone.val() + ' ');
}
if (phone.val().length === 9) {
phone.val(phone.val() + '-');
}
if (phone.val().length >= 14) {
phone.val(phone.val().slice(0, 13));
}
}
// Allow numeric (and tab, backspace, delete) keys only
return (key == 8 || // backspace
key == 9 ||
(key >= 48 && key <= 57)); //numeric
})
.on('keyup', function(e) {
var phone = $(this);
var key = e.charCode || e.keyCode || 0;
if (key !== 8 && key !== 9 && key >= 48 && key <= 57) {
if(keyPressVal==="("){
var currentKey = e.key;
if(currentKey.length==1 && currentKey!=="!"){
phone.val(keyPressVal+''+currentKey);
}
}
}
})
.on('focus', function() {
phone = $(this);
if (phone.val().length === 0) {
phone.val('(');
}
else {
var val = phone.val();
phone.val('').val(val); // Ensure cursor remains at the end
}
})
.on('blur', function() {
$phone = $(this);
if ($phone.val() === '(') {
$phone.val('');
}
});
}
function formatWebsite(){
$("div[data-id='"+dataId_website+"']").find("input")
.on('keypress', function(e) {
var website = $(this);
if (website.val().length == 0) {
website.val('http://');
} else if(website.val() === 'http://'){
keyPressVal = website.val();
} else {
keyPressVal = '';
}
})
.on('focus', function(e) {
website = $(this);
if (website.val().length == 0) {
website.val('http://');
}
})
.on('keyup', function(e) {
website = $(this);
if (website.val().length == 0) {
website.val('http://');
} else {
if(keyPressVal==="http://"){
var currentKey = e.key;
if(currentKey.length==1){
website.val(keyPressVal+''+currentKey);
}
}
}
})
.on('blur', function() {
$website = $(this);
if ($website.val() == 'http://') {
$website.val('');
}
});
}
function formatEOLiabilityLimits(){
$("div[data-id='"+dataId_eOLiabilityLimits+"']").find("input")
.on('keypress', function(e) {
var liabilityLimits = $(this);
if (liabilityLimits.val().length == 0) {
liabilityLimits.val(liabilityLimits.val() + '$');
}
})
.on('keyup', function(e) {
var keyLimits = e.charCode || e.keyCode || 0;
if (keyLimits != 8 && keyLimits != 9) {
var value = liabilityLimits.val().replace("$","");
var input = value.replace(/[\D\s\._\-]+/g, "");
const formatter = new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USD',
minimumFractionDigits: 0
})
input = formatter.format(input);
liabilityLimits.val(input);
// modify the hidden field as well
var priceHolder = $("div[data-id='"+dataId_eoLimitsHolder+"']").find("input");
var priceHolderNumber = parseInt(input.replace("$","").replace(/,/g, ""));
loader.engine.document.getElementById(parseInt(dataId_eoLimitsHolder)).setProperty('value.value' , priceHolderNumber);
}
return (keyLimits == 8 ||
keyLimits == 9 ||
keyLimits == 46 ||
(keyLimits >= 48 && keyLimits <= 57) ||
(keyLimits >= 96 && keyLimits <= 105));
})
.on('focus', function() {
liabilityLimits = $(this);
if (liabilityLimits.val().length == 0) {
liabilityLimits.val('$');
}
})
.on('blur', function() {
$liabilityLimits = $(this);
if ($liabilityLimits.val() == '$') {
$liabilityLimits.val('');
}
});
}
function formatYearEstablished() {
$("div[data-id='"+dataId_yearEstablished+"']").find("input")
.on('keypress', function(e) {
var year = $(this);
var key = e.charCode || e.keyCode || 0;
if (year.val().length == 0 && key == 48) {
return false; // zero not allowed as first digit
}
if (year.val().length >= 4) {
year.val(year.val().slice(0, 3));
}
// Allow numeric (and tab, backspace, delete) keys only
return (key == 8 || // backspace
key == 9 ||
(key >= 48 && key <= 57)); //numeric
});
}
function retrieveURL(){
var pageURL = $(location).attr("href");
var duplicateMsg = $("div[data-id='"+dataId_duplicateMessage+"']").find("input");
duplicateMsg.val(pageURL);
}
function returnHiddenValue(){
var hiddenReturnedAccount = $("div[data-id='"+dataId_hiddenReturnedAccount+"']").find("input");
// var hiddenReturnedAccount = loader.getEngine().getDocument().getElementById(dataId_hiddenReturnedAccount);
// var checker = loader.getEngine().getDocument().getElementById(dataId_checker);
// $("div[data-id='"+dataId_email+"']").find("input")
// .on('focus', function(e) {
// console.log('hiddenReturnedAccount--->>> ' + JSON.stringify(hiddenReturnedAccount.getValue()));
// })
// .on('blur', function(e) {
// console.log('hiddenReturnedAccount--->>> ' + JSON.stringify(hiddenReturnedAccount.getValue()));
// });
console.log(hiddenReturnedAccount.val() + " <-- hiddenReturnedAccount");
console.log(hiddenReturnedAccount.val().length + " <-- hiddenReturnedAccount length");
if (hiddenReturnedAccount.val().length != 0) {
checker.val("True");
}
}
function formatFields(){
// this will call all the formatters
formatPhone();
formatWebsite();
formatEOLiabilityLimits();
formatYearEstablished();
retrieveURL();
returnHiddenValue();
}
})(jQuery);