• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

limiting number input

Enthusiast ,
Aug 01, 2020 Aug 01, 2020

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.

TOPICS
Acrobat SDK and JavaScript

Views

428

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Aug 01, 2020 Aug 01, 2020

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";

Votes

Translate

Translate
Community Expert ,
Aug 01, 2020 Aug 01, 2020

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Aug 01, 2020 Aug 01, 2020

Copy link to clipboard

Copied

EDIT: I managed to make workaround, thx for your time.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 01, 2020 Aug 01, 2020

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";

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Aug 01, 2020 Aug 01, 2020

Copy link to clipboard

Copied

LATEST

Thank you so much for your help.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines