File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed
Client-Side Components/Catalog Client Script/Percentage Symbol Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change 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.
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments