- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2022 08:21 PM
HI All,
Can anyone please help us on the below requirement.
We have one field called "Count" and it's string type.
And when an end user enter any numbers in the field we need to automatically add the " - " symbol after every two numbers.
Examples:
--> 12-34-56
--> 32-3
--> 45
Advance thanks.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2022 03:44 AM
Hi All,
Many thanks for your response.
Below code working fine for us:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
// //Type appropriate comment here, and begin script below
var str = newValue.toString();
var tempdata='';
for (var i=0; i<str.length; i++){
if(str[i]!='-')
{
tempdata=tempdata+str[i];
//alert(tempdata);
}
}
//alert(tempdata);
var result='';
for (var j=0; j<tempdata.length; j++){
if(j%2!=0 && j!=tempdata.length-1)
{
result=result+tempdata[j]+'-';
}else{
result=result+tempdata[j];
}
}
//alert(result);
g_form.setValue('u_count', result);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2022 09:52 PM
You can create onChange() Catalog Client Script on your Count variable and use below script in your client script.
var str = newValue.toString();
var temp = str.slice(0, 2);
for (var i=2; i<str.length; i+=2){
temp += '-' + str.slice(i, i+2);
}
g_form.setValue('<backend_name_of_count_variable>', temp);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2022 09:59 PM
Background Script
Output
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2022 01:19 AM
Hi Muhammad,
Many thanks for the response.
we tried your script , but it's not working.
when we add the alerts to check the loop,
it's continuously running in the loop and it's not setting the value in the count field.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2022 10:27 PM
Hello,
You can do it by simple string manipulations
var NewCount = ''";
var Count = g_form.getValue('u_count');
for (var i = 0; i < Count.length; i++) {
if (i % 2 == 0 && i != 0) {
NewCount = NewCount + "-" + Count[i];
} else {
NewCount = NewCount + Count[i];
}
}
g_form.setValue('u_count', NewCount);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2022 02:37 AM
Hi Shubham,
Thanks for the response.
We tried your code but it's not working.
The instance is freezing.
Thanks.