Setting maximum character length for variables of multi-line text

Vinya Jakkula
Tera Contributor

Hi Team can anyone help me!! Iam using below script to limit the characters while using entering the text.it is working in native UI. But not in portal.as I know get control will not work in portal. Can anyone help me please.

 

function onLoad() {
    var control = g_form.getControl('comments');
    //Set its onkeyup method
    control.onkeyup = isMaxLength;

}


function isMaxLength() {
    var mLength = 170;
    var control = g_form.getControl('comments');
    if (control.value.length > mLength) {
        g_form.hideErrorBox('comments');
        g_form.showErrorBox('comments', 'You have reached the maximum character limit for this field.');
        control.value = control.value.substring(0, mLength);
    } else {
        g_form.hideErrorBox('comments');
    }
}
2 REPLIES 2

Shaqeel
Mega Sage

Hi @Vinya Jakkula 

 

Here is what I got:

Article 

function onSubmit() {
	var maxLength = 290; // Add desired max length here
	var varName = 'full_description'; // Add variable name here
	var multi = g_form.getValue(varName);
	var len = multi.length;
	if(len > maxLength){
		var str = multi.slice(0, maxLength);
		g_form.setValue(varName, str);
		g_form.showFieldMsg(varName, 'Max length of ' + maxLength.toString() + ' exceeded for this field.', 'error');
                return false;
	}
}

 

Regards

Shaqeel


***********************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting "Accept as Solution" and " Helpful." This action benefits both the community and me.

***********************************************************************************************************************





Regards

Shaqeel

With above script it will delete the user entered the text if it is beyond the limit. I need to on key while user typing the text.