the percentage field is allowing to write many numbers instead of below 100.

lakng
Tera Contributor

how can i set the percentage field which allows only below 100 numbers in the percentage field.

 

1 ACCEPTED SOLUTION

johansec
Tera Guru

You can make an OnChange Client script that validates the value is what you are expecting. 

Here is an example of the script I used. 

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

   if(newValue > 100){
	   g_form.setValue('percent_complete', 100);
	   g_form.showFieldMsg('percent_complete', 'Percent complete must be between 0 - 100.','error', false);
   }
	
	if(newValue < 0){
	   g_form.setValue('percent_complete', 0);
	   g_form.showFieldMsg('percent_complete', 'Percent complete must be between 0 - 100.','error', false);
   }
   
}

 

Create the script on change of the percentage field you have.

Check the newValue to ensure it is what you want and then do what you would like to the field. 

 

I set it to zero if it was below zero and to 100 if it was over 100 but you can set it to empty if you would like.

View solution in original post

1 REPLY 1

johansec
Tera Guru

You can make an OnChange Client script that validates the value is what you are expecting. 

Here is an example of the script I used. 

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

   if(newValue > 100){
	   g_form.setValue('percent_complete', 100);
	   g_form.showFieldMsg('percent_complete', 'Percent complete must be between 0 - 100.','error', false);
   }
	
	if(newValue < 0){
	   g_form.setValue('percent_complete', 0);
	   g_form.showFieldMsg('percent_complete', 'Percent complete must be between 0 - 100.','error', false);
   }
   
}

 

Create the script on change of the percentage field you have.

Check the newValue to ensure it is what you want and then do what you would like to the field. 

 

I set it to zero if it was below zero and to 100 if it was over 100 but you can set it to empty if you would like.