Highlighted

app.alert help

Contributor ,
Aug 01, 2020

Copy link to clipboard

Copied

I have field1 and field 2, on field 1 I have app.alert to limit me from entering specific value from field 2 even though field 1
doesn't calculate that value when alert pop it
still change value in field2. What I need to do so when I get alert that field2 stay same and doesn't change it's current value?

Adobe Community Professional
Correct answer by ls_rbls | Adobe Community Professional

Then modify my custom calculation script above for Field2 like this:

 

if (event.value <= 30) {
this.getField("Field1").value = event.value;
}  else {

if (event.value > 30) { event.value = this.getField("Field1").value;
 }
}

 

Don't change anything. Try it out first as instructed.

 

In the solution I am giving to you  the app alert is not executed in Field1. If you have any calutlations or app.alert scripts in Field1 get rid of it. Or we will continue like the chicken or the egg story of what came first.

 

Everything will run from Field2 in this example.

TOPICS
Acrobat SDK and JavaScript

Views

116

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

app.alert help

Contributor ,
Aug 01, 2020

Copy link to clipboard

Copied

I have field1 and field 2, on field 1 I have app.alert to limit me from entering specific value from field 2 even though field 1
doesn't calculate that value when alert pop it
still change value in field2. What I need to do so when I get alert that field2 stay same and doesn't change it's current value?

Adobe Community Professional
Correct answer by ls_rbls | Adobe Community Professional

Then modify my custom calculation script above for Field2 like this:

 

if (event.value <= 30) {
this.getField("Field1").value = event.value;
}  else {

if (event.value > 30) { event.value = this.getField("Field1").value;
 }
}

 

Don't change anything. Try it out first as instructed.

 

In the solution I am giving to you  the app alert is not executed in Field1. If you have any calutlations or app.alert scripts in Field1 get rid of it. Or we will continue like the chicken or the egg story of what came first.

 

Everything will run from Field2 in this example.

TOPICS
Acrobat SDK and JavaScript

Views

117

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
Aug 01, 2020 0
Most Valuable Participant ,
Aug 01, 2020

Copy link to clipboard

Copied

Please share your code or your file. 

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...
Aug 01, 2020 0
Contributor ,
Aug 01, 2020

Copy link to clipboard

Copied

I don't have code for field2.

in field1 is just simple calculation nothing more, app.alert comes from "field value is in range".

Just need help if alert pop, field2 also stay same, because now even though field1 doesn't change it's value if alert pop entered value in field2 stay in it.

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...
Aug 01, 2020 0
Most Valuable Participant ,
Aug 01, 2020

Copy link to clipboard

Copied

Please give us the actual code you already have. Please copy and paste it. Also please post your idea for the new code, even if wrong. We hope to help you learn how to write your code, not to just write it all for you.

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...
Aug 01, 2020 0
Contributor ,
Aug 01, 2020

Copy link to clipboard

Copied

var a = this.getField("field1").value;
var b = this.getField("field2");
if( a == (don't know what to write here if value in field1 didn't change)){
b = (value need to stay same if field1 didn't change);
}

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...
Aug 01, 2020 0
Contributor ,
Aug 01, 2020

Copy link to clipboard

Copied

Still need help with this one. 

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...
Aug 01, 2020 0
Most Valuable Participant ,
Aug 02, 2020

Copy link to clipboard

Copied

Thank you for your more detailed reply. Please allow a few days to see if someone sees your message who wants to help. Especially as it is the weekend and still the middle of the night in US.

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...
Aug 02, 2020 0
Adobe Community Professional ,
Aug 05, 2020

Copy link to clipboard

Copied

When you use following validation:

Bild1.jpg

Acrobat will display a message when you enter a wrong value. In this case Acrobat doesn't use app.alert.

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...
Aug 05, 2020 0
Adobe Community Professional ,
Aug 04, 2020

Copy link to clipboard

Copied

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...
Aug 04, 2020 0
Contributor ,
Aug 04, 2020

Copy link to clipboard

Copied

Sorry I don't see how those posts could help me?

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...
Aug 04, 2020 0
Adobe Community Professional ,
Aug 04, 2020

Copy link to clipboard

Copied

You asked about a popup alert.

 

The the structure of the scripts in those two discussions  is what I was trying to share with you as examples.

 

It shows how an alert is triggered based on a condition when a value changes in another field.

 

Isn't that what you're struggling with?

 

 

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...
Aug 04, 2020 0
Contributor ,
Aug 05, 2020

Copy link to clipboard

Copied

app.alert is not part of problem my problem is whats happening when alert pop.

il try to explain, in field1 I have default value of 30 and it's range is set from 0-30 so if i enter value larger then 30 I get alert and value is not writen then but it's still written in field2 where i'm entering that value,so what I need is if I enter in field2 value of 50 field1 will give alert and won't write value if that happen field2 also shouldn't write value, so basicaly if alert for field1 pop field2 also doesn't change.

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...
Aug 05, 2020 0
Adobe Community Professional ,
Aug 05, 2020

Copy link to clipboard

Copied

How does you change the value of field2?

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...
Aug 05, 2020 0
Contributor ,
Aug 05, 2020

Copy link to clipboard

Copied

I enter value in field2 with dialog box.

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...
Aug 05, 2020 0
Adobe Community Professional ,
Aug 05, 2020

Copy link to clipboard

Copied

Why does you use a dialog box for this?

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...
Aug 05, 2020 0
Contributor ,
Aug 05, 2020

Copy link to clipboard

Copied

because I have other info in dialog box that user need to see before entering values to field2

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...
Aug 05, 2020 0
Adobe Community Professional ,
Aug 05, 2020

Copy link to clipboard

Copied

When you don't want change the value in field2 then don't call the dialog box.

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...
Aug 05, 2020 0
Contributor ,
Aug 05, 2020

Copy link to clipboard

Copied

I don't wan't to change value in field2 only when field1 doesn't change it's value cuz of alert.pop. 

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...
Aug 05, 2020 0
Most Valuable Participant ,
Aug 05, 2020

Copy link to clipboard

Copied

I asked you to post your code, and it turns out there is all sorts of extra code with dialog boxes and everything. Please don't ask us to help while blindfolding us!!

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...
Aug 05, 2020 0
Contributor ,
Aug 05, 2020

Copy link to clipboard

Copied

Did any of you even read my OP? everything is explained there non of other codes or dialog boxes matter for my problem, either help me or don't ask me unnecessary questions.

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...
Aug 05, 2020 0
Adobe Community Professional ,
Aug 05, 2020

Copy link to clipboard

Copied

Is all good bro. 

 

It's just that people come here to the forums asking for complex stuff but they start with a very easy question....then they start adding more crap to the equation; in the end, having community memebers  do the work for them that otherwise should be paid for.

 

We will help you. But that had to be clarified and get it out of the way.

 

The way you're phrasing your inquiry each time seems like it changes all the time. Some of us also struggle with language barriers. 

 

But anyway, this is what I understood after re-reading this discussion a several times:

 

  • You have to two text fields. One is named Field1 , the other Field2. 
  • Whatever a user inputs manually in Field1 will autopopulate Field2. However, user is restricted from enter any value that is greater than 30 in Field1.
  • If the input value of Field1 is greater than 30, then an alert will trigger to notify the user that it can't greater than 30.
  • What you need is that when this condition is met, where a value is greater than 30 in Field1, that Field2 remains with the value that was entered in Field1 by the user ( which was greater than 30) but reset or clear Field1 after the alert dialogue box is closed and not alter Field2.

 

Is this correct , please confirm so we're all tracking the same information.

 

You're issue is not that hard to resolve.

 

All you need is probably a conditional statement, and I would say that maybe a validation script which will get this done.

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...
Aug 05, 2020 0
Contributor ,
Aug 05, 2020

Copy link to clipboard

Copied

sry and thx for helping english isn't my first language  so sorry if I don't express myself right.

I don't know how to explain it easier but Il try, field1 get it's value from field2 and field1 has app alert set for value range 0-30. if I enter  5 in field2 it will show in field1 and in field2(obviusly) but if I enter after that  50 in field2, field1 will pop alert and it's value will remain 5 but field2 value will now change to 50. what i need is if field1 stay at 5 field2 also should stay at 5 and not show 50.

 

EDIT: This is not valid code but it shows what would I like it to do,maybe it will be easier for you to understand.

var a = this.getField("Points").event;
if(a.event == app.alert){
this.getField("C2").value = ReturnValue;
}

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...
Aug 05, 2020 0
Adobe Community Professional ,
Aug 05, 2020

Copy link to clipboard

Copied

Do it like this:

 

In Field2 use put this script in the "Validate" tab --->> "Run custom validation script"  section

 

if (event.value > 30) {
app.alert("Invalid value. Please enter a value between 0-30", 0);
event.rc = true;
}

 

 

And then in the Calculate tab of Field2, use this script as custom calculation script:

 

 

if (event.value <= 30) {this.getField("Field1").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...
Aug 05, 2020 0
Adobe Community Professional ,
Aug 05, 2020

Copy link to clipboard

Copied

That's all you need really.

 

And I'm sure there's so many other ways to do it. 

 

But this is what work for me on my end.

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...
Aug 05, 2020 0
Adobe Community Professional ,
Aug 05, 2020

Copy link to clipboard

Copied

I forgot to add that you need to set your fields' custom format as Numbers.

 

Since Field 2  will control much of what happens, you also need to set a range from 0 to 30 in Field1 and lock it. This allows the script From Field2 to work as described in my reply above, but if the user wants to manually change the Field1 value manually it won't allow to enter anything that is greater than 30..

 

See slide:

 

validatearange.png 

 

Don't complicate yourself too much. Sometimes is better to use Acrobat's built-in features. In fact, I've seen experienced ACP's recommend this too. 

 

If there's a result you can achieve without JavaScript then use it. This will keep work work somewhat more simplified and less prone to errors and testing.

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...
Aug 05, 2020 0
Contributor ,
Aug 05, 2020

Copy link to clipboard

Copied

Sorry but it's not working for me as intended. All I need is if I get app.alert from field1 after entering value in field2, field2 need to return to it's previous value before app.alert.

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...
Aug 05, 2020 0
Most Valuable Participant ,
Aug 05, 2020

Copy link to clipboard

Copied

You are talking as if the app.alert is changing things. Alerts DO NOT CHANGE FIELDS. Your code does. ALERTS CANNOT RUN JAVASCRIPT. You have never posted the code with the app.alert in it, you are still hiding so much from us. This is very frustrating, would you expect to help you fix your car if you won't tell them about the problems !!

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...
Aug 05, 2020 0
Contributor ,
Aug 05, 2020

Copy link to clipboard

Copied

here is my file PDF try adding values and see what happen when you add above 30.

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...
Aug 05, 2020 0
Adobe Community Professional ,
Aug 05, 2020

Copy link to clipboard

Copied

Then modify my custom calculation script above for Field2 like this:

 

if (event.value <= 30) {
this.getField("Field1").value = event.value;
}  else {

if (event.value > 30) { event.value = this.getField("Field1").value;
 }
}

 

Don't change anything. Try it out first as instructed.

 

In the solution I am giving to you  the app alert is not executed in Field1. If you have any calutlations or app.alert scripts in Field1 get rid of it. Or we will continue like the chicken or the egg story of what came first.

 

Everything will run from Field2 in this example.

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...
Aug 05, 2020 0
Adobe Community Professional ,
Aug 05, 2020

Copy link to clipboard

Copied

Look at the field names that I used in my examples:

 

this.getField("Field1").value;

 

In your file you're using "field1"   the "f" is in lower case in your PDF. The fieldnames must match exactly how they're spelled or it won't work.

 

Here's your fixed file:

 

 

 

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...
Aug 05, 2020 0
Adobe Community Professional ,
Aug 05, 2020

Copy link to clipboard

Copied

May be better when you use a custom validation 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...
Aug 05, 2020 1
Asim123 LATEST
Contributor ,
Aug 05, 2020

Copy link to clipboard

Copied

Thanks I already modify it, it's working even if app.alert is in field1, thanks again for your help.

 

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...
Aug 05, 2020 1