remove empty lines(middle of text) in field

gtk
Mega Sage

on the change table, we have a change client script on the type field

if type - emergency then on description field a static text will be added and then the actual description comes

while testing in use-cases we found few issues

1. if the user enters in description first and chooses TYPE then it is working as expected

description: static text 

user entered description

find_real_file.png

2. if the user enters description first and chooses TYPE (changing this field as many times from emergency to standard, emergency to other) in this case we are getting empty lines between static text and user-entered description

find_real_file.png

any help appreciated

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue == '') {
        return;
    }
	var newtext = "static text";
	var desc = g_form.getValue('description').toString().replace( /(\r\n|\n|\r)/g, "" );
	var newdesc;
    if (newValue == 'emergency') {
        newdesc = newtext + '\n' +desc;
        g_form.setValue('description', newdesc);
    } else  {
		if(desc.indexOf(newtext)>-1){
		var newdesc1 = desc.toString().split(newtext)[1].toString().replace( /\\n/g, "" );
			//if(newdesc1.trim()!=''){
			//newdesc = desc.split('Given Description : ');
			//if(newdesc.length > 1 ){
			
				g_form.setValue('description',newdesc1);
		}
			}
		}
  

 

 

 

1 REPLY 1

Bhagyashri Sort
Kilo Guru

Hi,

 As you write the onChange client script, it get executed every time whenever you are changing the field value, thats why thes whitespace are get included.  Try by using trim() function of string to remove white spaces.

https://www.w3schools.com/jsref/jsref_trim_string.asp

 

Mark it correct and helpful.

Thanks

Bhagyashri Sorte.