Copy link to clipboard
Copied
I have field "points" that shows value 30/30, and 3 other fields(C1,C2,C3) for entering values which then substracts from field "points".
How do I make it so field "points" can't go bellow 0, it only allow up to 0? for example if I want to enter 31 in field "C1" it
doesn't allow me.
INFO:
Field "points" have default value of 30 and use custom calculation script:
var a = this.getField("points").defaultValue;
var b = this.getField("C1").value;
var c = this.getField("C2").value;
var d = this.getField("C3").value;
var x = a-b-c-d;
event.value = x + "/30";
It doesn't allow me to enter "Field value is in range" which I could use to solve my problem, I can only enter custom validation script.
I also have 3 buttons each for fields C1,C2,C3 with dialog boxes where user input numbers which is then writed to fields C1,C2,C3.
I think that I need custom validation script for field "points" but not sure how to write one.
Replace the last line of your code with this:
if (x<0 || x>30) {app.alert("The numbers you entered are not valid."); event.value = ""; }
else event.value = x + "/30";
Copy link to clipboard
Copied
You should be able to use the Validate event in your field, but you have to set it as having a Number format. However, the value you're applying to it in the calculation script is not a number, but a string, because of the addition of "/30" in the last line of code. If you want to validate the value of the x variable before applying this string you should do so in your calculation script. Or you could add the "/30" string in a Format script, so it doesn't affect the actual field value.
Copy link to clipboard
Copied
EDIT: I managed to make workaround, thx for your time.
Copy link to clipboard
Copied
Replace the last line of your code with this:
if (x<0 || x>30) {app.alert("The numbers you entered are not valid."); event.value = ""; }
else event.value = x + "/30";
Copy link to clipboard
Copied
Thank you so much for your help.