Skip to content

Commit a2060e1

Browse files
authored
Client script to Set percentage (#2657)
* Create script.js * Create readme.md
1 parent d9e42aa commit a2060e1

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Sets the field value to the formatted percentage string (e.g., 45 becomes 45.00%).
2+
3+
Retrieves the current value of the field.
4+
Removes any existing % symbol to avoid duplication.
5+
Validates the input to ensure it's a number.
6+
Converts the value to a float.
7+
Formats it to two decimal places and appends a % symbol.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*Sets the field value to the formatted percentage string (e.g., 45 becomes 45.00%).
2+
3+
Retrieves the current value of the field.
4+
Removes any existing % symbol to avoid duplication.
5+
Validates the input to ensure it's a number.
6+
Converts the value to a float.
7+
Formats it to two decimal places and appends a % symbol. */
8+
9+
10+
function onChange(control, oldValue, newValue, isLoading) {
11+
if (isLoading || newValue == '') {
12+
return;
13+
}
14+
15+
function formatPercent(value) {
16+
if (value === null || value === undefined || value === '' || isNaN(value)) {
17+
return "";
18+
}
19+
var num = parseFloat(value);
20+
if (isNaN(num))
21+
return "";
22+
return num.toFixed(2) + "%";
23+
}
24+
var des_amount = g_form.getValue("<variable_name>").replace("%","");
25+
26+
g_form.setValue("<variable_name>", formatPercent(des_amount));
27+
28+
}

0 commit comments

Comments
 (0)