16
16
var received_ts = new Date ( received ) ;
17
17
var received_iso = received_ts . toISOString ( ) ;
18
18
19
+ var errors = [ ] ;
20
+
19
21
// Add regular expression check for number of employees
20
22
var employeesRegex = / ^ [ 0 - 9 ] + $ / ;
21
23
if ( ! employeesRegex . test ( employees ) ) {
22
- alert ( "Please enter only numbers in the Employees field" ) ;
23
- return ;
24
- }
24
+ const employeesError = document . getElementById ( "employees-error" ) ;
25
+ employeesError . style . display = "block" ;
26
+ const employeesField = document . getElementById ( "employees" ) ;
27
+ employeesField . style . outline = "2px solid red" ;
28
+ errors . push ( "Employees is invalid" ) ;
29
+ } else {
30
+ const employeesError = document . getElementById ( "employees-error" ) ;
31
+ employeesError . style . display = "none" ;
32
+ const employeesField = document . getElementById ( "employees" ) ;
33
+ employeesField . style . outline = "" ;
34
+ }
35
+
25
36
26
37
// Add regular expression check for total billed
27
38
var billedRegex = / ^ [ 0 - 9 ] + $ / ;
28
39
if ( ! billedRegex . test ( totalBilled ) ) {
29
- alert ( "Please enter only numbers in the Total Billed field" ) ;
30
- return ;
31
- }
40
+ billedError = document . getElementById ( "billed-error" ) ;
41
+ billedError . style . display = "block" ;
42
+ totalBilled = document . getElementById ( "totalBilled" ) ;
43
+ totalBilled . style . outline = "2px solid red" ;
44
+ errors . push ( "Total Billed is invalid" ) ;
45
+ } else {
46
+ const billedError = document . getElementById ( "billed-error" ) ;
47
+ billedError . style . display = "none" ;
48
+ const totalBilled = document . getElementById ( "totalBilled" ) ;
49
+ totalBilled . style . outline = "" ;
50
+ }
32
51
33
- var output = `{
52
+ if ( errors . length > 0 ) {
53
+ // Display all the errors and highlight the respective fields
54
+ const errorDiv = document . getElementById ( "errors" ) ;
55
+ errorDiv . innerHTML = "" ;
56
+ errors . forEach ( function ( error ) {
57
+ errorDiv . innerHTML += "<p>" + error + "</p>" ;
58
+ } ) ;
59
+ return false ;
60
+ }
61
+
62
+ var output = `{
34
63
"anonymousId": "507f191e810c19729de860ea",
35
64
"channel": "browser",
36
65
"context": {
59
88
"version": "1.1"
60
89
}` ;
61
90
91
+ var output_container = document . getElementById ( "output_container" ) ;
62
92
output_container . innerHTML = output ;
63
93
Prism . highlightElement ( output_container ) ;
64
- }
65
- </ script >
94
+ return true ;
95
+ }
96
+
97
+ </ script >
66
98
67
99
< script >
68
100
function showOutput ( ) {
@@ -86,10 +118,12 @@ <h3> Sample Group call</h3>
86
118
< input type ="text " id ="industry " value ="Beauty ">
87
119
< label for ="employees "> Employees:</ label >
88
120
< input type ="text " id ="employees " value ="200 ">
121
+ < span class ="error-message " id ="employees-error "> Please enter a valid number of employees.</ span >
89
122
< label for ="plan "> Plan:</ label >
90
123
< input type ="text " id ="plan " value ="Premium ">
91
124
< label for ="totalBilled "> Total Billed:</ label >
92
125
< input type ="text " id ="totalBilled " value ="34000 ">
126
+ < span class ="error-message " id ="billed-error "> Please enter only numbers in the Total Billed field.</ span >
93
127
< input type ="submit " class ="button button-hollow " id ="submit " onclick ="showMessage(); showOutput() "
94
128
value ="See a sample group call ">
95
129
</ div >
0 commit comments