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

Akhil41
Giga Contributor

Can you elaborate a bit on your requirement? What field value you wanna restrict and to which values?

Hi

I am trying to restrict the filed values by using configure dictionary, but it is not allow because all ready some records is their. thus why i'm trying on change client scripts. i'm tried below code, but my point is  user wants to enter only 10 character not more than.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
// if(oldValue!=newValue)

var r=g_form.getValue('short_description');
var l=r.length;
if(l>10)
{
var t=r.slice(0,10);
g_form.setValue('short_description',t);
g_form.showFieldMsg('short_description','....................');
}

Hi JMR,

 

You can achieve the same via an onChange Client Script on change of that field. For example if you want to restrict the user from entering 10 character in the 'Short description' field, then you need to define the Client Script as below:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
 if (isLoading || newValue === '') {
 return;
 }

 //Check whether the field value is greater than 10 characters
 if(newValue.length>10) {
    g_form.clearValue('short_description'); //Clear the field value
    alert('Please provide the field value of 10 Character at maximum'); //Show the alert message to the user
 }

}

 

Hope this helps. Please mark the answer Correct/Helpful based on the impact.

Regards,

Amlan

Hi JMR,

 

Just following up with my last response. Did you able to validate the solution I have provided? Please let me know if you are still facing the issue?

 

Regards,

Amlan