|
1 | 1 | function onChange(control, oldValue, newValue, isLoading) {
|
2 |
| - if (isLoading || newValue == '') { |
3 |
| - return; |
4 |
| - } |
5 |
| - var cost = g_form.getValue('variable_name'); //update variable name used for currency |
6 |
| - cost = cost.trim(); |
7 |
| - // first character should be dollar sign |
8 |
| - var firstChar = cost.substring(0,1); |
9 |
| - if (firstChar != '$') { |
10 |
| - alert ("Please enter cost in $0.00 format"); |
11 |
| - g_form.setValue("daily_rate", oldValue); |
12 |
| - return; |
13 |
| - } |
| 2 | + if (isLoading || newValue == '') { |
| 3 | + return; |
| 4 | + } |
| 5 | + |
| 6 | + var cost = g_form.getValue('variable_name'); //update variable name used for currency |
| 7 | + cost = cost.trim(); |
| 8 | + // first character should be dollar sign |
| 9 | + var firstChar = cost.substring(0, 1); |
| 10 | + if (firstChar != '$') { |
| 11 | + validationAlert(oldValue); |
| 12 | + } |
14 | 13 |
|
15 |
| - // characters after the $ sign should be numerics |
16 |
| - var costType = isNaN(cost.substring(1)); |
17 |
| - if (costType == true) { |
18 |
| - alert ("Please enter cost in $0.00 format"); |
19 |
| - g_form.setValue("daily_rate", oldValue); |
20 |
| - return; |
21 |
| - } |
| 14 | + // characters after the $ sign should be numerics |
| 15 | + var costType = isNaN(cost.substring(1)); |
| 16 | + if (costType == true) { |
| 17 | + validationAlert(oldValue); |
| 18 | + } |
22 | 19 |
|
23 |
| - // entered value should have a decimal point |
24 |
| - var num = cost.substring(1); |
25 |
| - if (num.indexOf('.') == -1) { |
26 |
| - alert ("Please enter cost in $0.00 format"); |
27 |
| - g_form.setValue("daily_rate", oldValue); |
28 |
| - return; |
29 |
| - } |
| 20 | + // entered value should have a decimal point |
| 21 | + var num = cost.substring(1); |
| 22 | + if (num.indexOf('.') == -1) { |
| 23 | + validationAlert(oldValue); |
| 24 | + } |
30 | 25 |
|
31 |
| - // there must be 2 digits only after the decimal |
32 |
| - var decNum = num.substring(num.indexOf('.')+1, num.length); |
33 |
| - if (decNum.length != 2) { |
34 |
| - alert ("Please enter cost in $0.00 format"); |
35 |
| - g_form.setValue("daily_rate", oldValue); |
36 |
| - return; |
37 |
| - } |
| 26 | + // there must be 2 digits only after the decimal |
| 27 | + var decNum = num.substring(num.indexOf('.') + 1, num.length); |
| 28 | + if (decNum.length != 2) { |
| 29 | + validationAlert(oldValue); |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +function validationAlert(oldValue) { |
| 34 | + g_form.setValue("variable_name", oldValue); |
| 35 | + var gm = new GlideModal("glide_warn"); |
| 36 | + gm.setTitle("Currency formatting problem"); |
| 37 | + gm.setPreference("title", "Please enter cost in $0.00 format"); |
| 38 | + gm.render(); |
| 39 | + return; |
38 | 40 | }
|
0 commit comments