limit characters of multiline text

Vinya Jakkula
Tera Contributor
Hi Team,
can anyone please help me.Below script is working in native UI. When user typing itself, it will stop if user entered more than the characters mentioned in script.i required the same way work in portal.
 
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');
    }
}
6 REPLIES 6

Jaspal Singh
Mega Patron
Mega Patron

Hi Vinya,

Why not limit it by simplying setting the max_length attribute as anyways, the script of yours is executing onLoad and not onChange or onSubmit.

But for multiline text max length is not working.

Hi @Sid_Takali  above link not referring the multi-line text.