Need client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-18-2024 07:40 AM
For a variable (number) - it should accept only whole number ex:12 after that it need to autopopulate as ($12.00) including decimal and dollar symbol.
If alphabets or or any other apart from whole numbers are entered then it should show error.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-18-2024 08:13 AM
Hi @User_267 ,
You can try below code
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
// Check if the new value contains only numbers
if (/^\d+$/.test(newValue)) {
// Format the value as $xx.xx
var formattedValue = '$' + parseFloat(newValue).toFixed(2);
// Set the formatted value back to the field
g_form.setValue('amount', formattedValue);
} else {
// Display an error message
g_form.addErrorMessage('Please enter a valid whole number.');
// Reset the field value to the previous value
g_form.clearValue('amount');
}
}
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-18-2024 08:24 AM
Even for numbers like 12 it is showing alert.