diff --git a/Client-Side Components/Catalog Client Script/Percentage Symbol/readme.md b/Client-Side Components/Catalog Client Script/Percentage Symbol/readme.md new file mode 100644 index 0000000000..61268653b8 --- /dev/null +++ b/Client-Side Components/Catalog Client Script/Percentage Symbol/readme.md @@ -0,0 +1,7 @@ +Sets the field value to the formatted percentage string (e.g., 45 becomes 45.00%). + +Retrieves the current value of the field. +Removes any existing % symbol to avoid duplication. +Validates the input to ensure it's a number. +Converts the value to a float. +Formats it to two decimal places and appends a % symbol. diff --git a/Client-Side Components/Catalog Client Script/Percentage Symbol/script.js b/Client-Side Components/Catalog Client Script/Percentage Symbol/script.js new file mode 100644 index 0000000000..1685dad322 --- /dev/null +++ b/Client-Side Components/Catalog Client Script/Percentage Symbol/script.js @@ -0,0 +1,28 @@ +/*Sets the field value to the formatted percentage string (e.g., 45 becomes 45.00%). + +Retrieves the current value of the field. +Removes any existing % symbol to avoid duplication. +Validates the input to ensure it's a number. +Converts the value to a float. +Formats it to two decimal places and appends a % symbol. */ + + +function onChange(control, oldValue, newValue, isLoading) { + if (isLoading || newValue == '') { + return; + } + + function formatPercent(value) { + if (value === null || value === undefined || value === '' || isNaN(value)) { + return ""; + } + var num = parseFloat(value); + if (isNaN(num)) + return ""; + return num.toFixed(2) + "%"; +} +var des_amount = g_form.getValue("").replace("%",""); + +g_form.setValue("", formatPercent(des_amount)); + +}