Conflict between two JavaScripts (I think)

Participant ,
Oct 21, 2019

Copy link to clipboard

Copied

This has been driving me nuts for a few hours and I've just realised what I think the problem is, but I don't know who to rectify it.

 

In all fields, I have the following custom validation script so I don't get a form full of zeros

if(event.value == 0 | event.value == '') event.value = '';

 

Problem is, in another field I have the following which says I want a specific field to show zeros, which it's not doing, I'm guessing because of the custom validation script.

 

if (this.getField("vat rate.10").value == "Exempt") {
event.value = 0;
}
else {
event.value = this.getField("vat rate.10").value/ 100.0;
}

 

If I remove the custom validation script, I obviously get a load to zeros appearing. Help please!

Adobe Community Professional
Correct answer by Bernd Alheit | Adobe Community Professional

You can use this:

if (this.getField("vat rate.10").value == "Exempt") {
event.value = 0;
} else {
event.value = Number(this.getField("aVATRate.10").valueAsString) * Number(this.getField("net value.10").valueAsString);
if (event.value == 0) event.value = '';
}
TOPICS
Acrobat SDK and JavaScript, PDF forms

Views

492

Likes

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

Conflict between two JavaScripts (I think)

Participant ,
Oct 21, 2019

Copy link to clipboard

Copied

This has been driving me nuts for a few hours and I've just realised what I think the problem is, but I don't know who to rectify it.

 

In all fields, I have the following custom validation script so I don't get a form full of zeros

if(event.value == 0 | event.value == '') event.value = '';

 

Problem is, in another field I have the following which says I want a specific field to show zeros, which it's not doing, I'm guessing because of the custom validation script.

 

if (this.getField("vat rate.10").value == "Exempt") {
event.value = 0;
}
else {
event.value = this.getField("vat rate.10").value/ 100.0;
}

 

If I remove the custom validation script, I obviously get a load to zeros appearing. Help please!

Adobe Community Professional
Correct answer by Bernd Alheit | Adobe Community Professional

You can use this:

if (this.getField("vat rate.10").value == "Exempt") {
event.value = 0;
} else {
event.value = Number(this.getField("aVATRate.10").valueAsString) * Number(this.getField("net value.10").valueAsString);
if (event.value == 0) event.value = '';
}
TOPICS
Acrobat SDK and JavaScript, PDF forms

Views

493

Likes

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
Oct 21, 2019 0
Adobe Community Professional ,
Oct 21, 2019

Copy link to clipboard

Copied

Use the script as calculation script.

Likes

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
Reply
Loading...
Oct 21, 2019 0
Participant ,
Oct 21, 2019

Copy link to clipboard

Copied

Sorry, don't understand.

One is a custom validation and the other is in custom calculation. If I delete the custom validation script, I get zeros appear in all fields even if there is nothing there - see below.

clipboard_image_0.png

Likes

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
Reply
Loading...
Oct 21, 2019 0
Most Valuable Participant ,
Oct 21, 2019

Copy link to clipboard

Copied

If you have a validation script that stops zeros from apprearing, they will not appear. So you need to do this check ONLY when calculating, not when validating. Merge into one script.

Likes

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
Reply
Loading...
Oct 21, 2019 0
Participant ,
Oct 21, 2019

Copy link to clipboard

Copied

This doesn't work, so I know I haven't done it correctly....  😞

 

if (this.getField("vat rate.10").value == "Exempt") {
event.value = 0;
} else {
event.value = Number(this.getField("aVATRate.10").valueAsString) * Number(this.getField("net value.10").valueAsString);
}
} else {
event.value == 0 | event.value == '') event.value = '';
}

Likes

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
Reply
Loading...
Oct 21, 2019 0
Most Valuable Participant ,
Oct 21, 2019

Copy link to clipboard

Copied

You can't have two else-clauses for a single if-statement. That doesn't make sense.

Likes

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
Reply
Loading...
Oct 21, 2019 0
Participant ,
Oct 21, 2019

Copy link to clipboard

Copied

Ok, noted. So how do I merge everything into one script that only puts zeros in the field if Exempt is shown otherwise, the field is blank?

Thanks

Likes

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
Reply
Loading...
Oct 21, 2019 0
Adobe Community Professional ,
Oct 21, 2019

Copy link to clipboard

Copied

You can use this:

if (this.getField("vat rate.10").value == "Exempt") {
event.value = 0;
} else {
event.value = Number(this.getField("aVATRate.10").valueAsString) * Number(this.getField("net value.10").valueAsString);
if (event.value == 0) event.value = '';
}

Likes

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
Reply
Loading...
Oct 21, 2019 1
jlehane LATEST
Participant ,
Oct 22, 2019

Copy link to clipboard

Copied

Thank you Bernd - that works great, much appreciated

Likes

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
Reply
Loading...
Oct 22, 2019 0