How can i restriction the filed value by using client script.

JMR2
Mega Expert

Hi all,

I have requirement, can I restrict the field value by using client script.

thanks in advance.

13 REPLIES 13

Hi satheesh, 

can you please send me the link.

thanks in advance.

asifnoor
Kilo Patron

Hi,

You can restrict to 10 chars like below.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
 if (isLoading || newValue === '') {
 return;
 }
 if(newValue.length>10) {
    g_form.showFieldMsg('short_description','....................');
 }

}

Mark the comment as a correct answer and helpful once worked.

Hi asifnoor,

ur code some what's ok , but my requirement is user doesn't enter more 10char.

thanks,  

Hi,

We don't have key event listeners in service is which checks on every key input.

You can only validate the length after the input is given.

So you can write onchange on this field and check the length and if it's greater than 10, then raise an error and reset the field.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
 if (isLoading || newValue === '') {
 return;
 }
 if(newValue.length>10) {
    g_form.showFieldMsg('short_description','....................');
    g_form.clearValue("field name");
 }

}


Mark the comment as a correct answer and helpful if it answers your question.