Integer validation

Daniel Voutt
Tera Contributor

Hi,

I want to add a simple validation to a custom integer field.  I can see how the validation scripts work, and that there is a script to do exactly what I need, however, I cannot see how I can link the validation script to the custom field.

The field is called u_minutes and is within the incident table.

Any guidance that could be provided would be greatly appreciated.

Thanks in advance,

 

Dan

1 ACCEPTED SOLUTION

Hmm.. I never thought about it, but it doesn't seem to be the validation script that turns it into a 0, it must be something else. But is it possible that the value never should be 0? then you should able to do a onChange for that field like this:

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
     if (isLoading || newValue == '') {
           return;
     }
 if (newValue == 0){
	 g_form.showErrorBox('u_nummer','Please fill in a correct number');
 }
}

View solution in original post

8 REPLIES 8

Hmm.. I never thought about it, but it doesn't seem to be the validation script that turns it into a 0, it must be something else. But is it possible that the value never should be 0? then you should able to do a onChange for that field like this:

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
     if (isLoading || newValue == '') {
           return;
     }
 if (newValue == 0){
	 g_form.showErrorBox('u_nummer','Please fill in a correct number');
 }
}

siva_
Giga Guru
You can have an on change client script with regex validation and that will work Thanks Siva

Daniel Voutt
Tera Contributor

Thanks all - I actually used this:

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
if (newValue == 0){
alert('Please enter a numerical value in the "Minutes" field');
g_form.setValue('u_minutes','');
}
}

 

This will send an alert and reset the field value back to empty otherwise they are able to submit the form as it was defaulting to a "0"

Yes just was about to tell as showErrorBox proposed by Goran would only give a UI level error message but allows the user to submit the form. Anyways you just modified to what it can be 

Thanks, Siva