From 8c05bbe6ad2401d0522c652d8da502ebb3ada51e Mon Sep 17 00:00:00 2001 From: niamccash <39105458+niamccash@users.noreply.github.com> Date: Fri, 6 Oct 2023 13:13:19 -0400 Subject: [PATCH 1/2] Use GlideModal instead of alert Also tried to optimize repeated code --- .../currency_validation.js | 68 ++++++++++--------- 1 file changed, 35 insertions(+), 33 deletions(-) diff --git a/Catalog Client Script/Currency Validation/currency_validation.js b/Catalog Client Script/Currency Validation/currency_validation.js index 882fff6c09..7e9724bc5d 100644 --- a/Catalog Client Script/Currency Validation/currency_validation.js +++ b/Catalog Client Script/Currency Validation/currency_validation.js @@ -1,38 +1,40 @@ function onChange(control, oldValue, newValue, isLoading) { - if (isLoading || newValue == '') { - return; - } - var cost = g_form.getValue('variable_name'); //update variable name used for currency - cost = cost.trim(); - // first character should be dollar sign - var firstChar = cost.substring(0,1); - if (firstChar != '$') { - alert ("Please enter cost in $0.00 format"); - g_form.setValue("daily_rate", oldValue); - return; - } + if (isLoading || newValue == '') { + return; + } + + var cost = g_form.getValue('variable_name'); //update variable name used for currency + cost = cost.trim(); + // first character should be dollar sign + var firstChar = cost.substring(0, 1); + if (firstChar != '$') { + validationAlert(oldValue); + } - // characters after the $ sign should be numerics - var costType = isNaN(cost.substring(1)); - if (costType == true) { - alert ("Please enter cost in $0.00 format"); - g_form.setValue("daily_rate", oldValue); - return; - } + // characters after the $ sign should be numerics + var costType = isNaN(cost.substring(1)); + if (costType == true) { + validationAlert(oldValue); + } - // entered value should have a decimal point - var num = cost.substring(1); - if (num.indexOf('.') == -1) { - alert ("Please enter cost in $0.00 format"); - g_form.setValue("daily_rate", oldValue); - return; - } + // entered value should have a decimal point + var num = cost.substring(1); + if (num.indexOf('.') == -1) { + validationAlert(oldValue); + } - // there must be 2 digits only after the decimal - var decNum = num.substring(num.indexOf('.')+1, num.length); - if (decNum.length != 2) { - alert ("Please enter cost in $0.00 format"); - g_form.setValue("daily_rate", oldValue); - return; - } + // there must be 2 digits only after the decimal + var decNum = num.substring(num.indexOf('.') + 1, num.length); + if (decNum.length != 2) { + validationAlert(oldValue); + } +} + +function validationAlert(oldValue) { + g_form.setValue("variable_name", oldValue); + var gm = new GlideModal("glide_warn"); + gm.setTitle("Currency formatting problem"); + gm.setPreference("title", "Please enter cost in $0.00 format"); + gm.render(); + return; } From ac97dd520540e0359f9c52c7eecb97c1d6c647ec Mon Sep 17 00:00:00 2001 From: niamccash <39105458+niamccash@users.noreply.github.com> Date: Fri, 6 Oct 2023 13:17:01 -0400 Subject: [PATCH 2/2] Fixed indentation --- .../Currency Validation/currency_validation.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Catalog Client Script/Currency Validation/currency_validation.js b/Catalog Client Script/Currency Validation/currency_validation.js index 7e9724bc5d..95fa435479 100644 --- a/Catalog Client Script/Currency Validation/currency_validation.js +++ b/Catalog Client Script/Currency Validation/currency_validation.js @@ -2,13 +2,13 @@ function onChange(control, oldValue, newValue, isLoading) { if (isLoading || newValue == '') { return; } - + var cost = g_form.getValue('variable_name'); //update variable name used for currency cost = cost.trim(); // first character should be dollar sign var firstChar = cost.substring(0, 1); if (firstChar != '$') { - validationAlert(oldValue); + validationAlert(oldValue); } // characters after the $ sign should be numerics @@ -26,15 +26,15 @@ function onChange(control, oldValue, newValue, isLoading) { // there must be 2 digits only after the decimal var decNum = num.substring(num.indexOf('.') + 1, num.length); if (decNum.length != 2) { - validationAlert(oldValue); + validationAlert(oldValue); } } function validationAlert(oldValue) { - g_form.setValue("variable_name", oldValue); - var gm = new GlideModal("glide_warn"); - gm.setTitle("Currency formatting problem"); - gm.setPreference("title", "Please enter cost in $0.00 format"); - gm.render(); - return; + g_form.setValue("variable_name", oldValue); + var gm = new GlideModal("glide_warn"); + gm.setTitle("Currency formatting problem"); + gm.setPreference("title", "Please enter cost in $0.00 format"); + gm.render(); + return; }