Copy link to clipboard
Copied
I'm trying to hide a field when another field contains a certain value.
It works when I use it on "prepare form" but the script is not launch on startup.
I tried it with document's javascript and it look like nothing happens.
I'm using Adobe Acrobat DC 2019.0.21.20056.
Thanks for your help.
Copy link to clipboard
Copied
So, according the information you gave me, the solution I applied is :
Add an action to the first field on the document when it's selected.
It launches my javascript code.
In this way, the user just have to click on the first field to apply the script.
Thanks for your help.
Copy link to clipboard
Copied
In your document scripts, make sure you do not have it in a function. If in doubt show a screen shot. Also check the console for messages.
Copy link to clipboard
Copied
It's not on a function.
I know the script works, but not before opening the script editor...
Copy link to clipboard
Copied
What script does you use? Where does you use the script?
Copy link to clipboard
Copied
This one :
var test = this.getField("p1_data_ismarie");
var aEffacer = this.getField("p1_data2_veuf_de");
if(test.value=='X '){
aEffacer.display = display.hidden;
}
Copy link to clipboard
Copied
Where does you use the script?
Copy link to clipboard
Copied
On javascript tool (bottom right)>Document scripts(top middle)>modify
The script is launching only if y go there, then I click OK
Copy link to clipboard
Copied
Document scripts are executed when the PDF is opened. If you are experiencing an issue, then there is something else interfering with the script. Please post your PDF and we'll look at it.
Copy link to clipboard
Copied
Thanks, you can find both files (data and model) here : https://easyupload.io/1saqdb
Copy link to clipboard
Copied
Your script will be executed when you open the document.
Copy link to clipboard
Copied
this is my issue.... it's not working, the field "p1_data_ismarie" contains a value ("X ") but the action is done only when I open the javascript edit then I click ok to close it....
Copy link to clipboard
Copied
Fill the field, save and close the document. What happens when you open the saved document?
Copy link to clipboard
Copied
Absolutely nothing before I'm going on the javascript menu (then click edit then ok)
Copy link to clipboard
Copied
Ah, I see you have an XFDF file. I also see that the PDF is empty, so p1_data_ismarie will never be 'X ' . You talk about "opening" the file. But are you actually opening the XFDF which opens the PDF?
The flow is:
- the PDF is opened
- document open scripts are run
- the XFDF file is imported to change fields
So the document open scripts are not affected by the contents of the XFDF.
Copy link to clipboard
Copied
I'm opening the xfdf file then it asks me to choose the pdf file.
It means that I need that my script waits for the importation before launching the script?
Is it possible? May I do a loop with a setTimeOut?
Copy link to clipboard
Copied
I don't think you can do what you want to do. Document open will happen before import. The way you trigger the import is not important. Document open MUST happen before import because the import may rely on form field changes made during document open actions. Back to the drawing board, I think. Why not put the final data in the XFDF?
Copy link to clipboard
Copied
Final datas are in the xfdf....
The script modify the behaviour of a field in a certain one (data) has a specific value.
Copy link to clipboard
Copied
Why is the file being opened by the XFDF? Maybe there is a better way. Tell us what you are trying to do.
Copy link to clipboard
Copied
The user open the xfdf then it's automatically importing it on the pdf file.
I want to erase a text field (data) if an element is checked (data).
Copy link to clipboard
Copied
It sounds like you want two incompatible features. Data loaded with the XFDF and data manipulation with scripts. It's not easy to have both.
But to start. A document script is the wrong place to modify form field data. The document script is for setting up scripts and performing initialzation tasks.
To manipulate field data, use the field events related to field data changes. These events are triggered in all cases where field data is changed, whether it's from user input, script changes, or data import.
Copy link to clipboard
Copied
So, according the information you gave me, the solution I applied is :
Add an action to the first field on the document when it's selected.
It launches my javascript code.
In this way, the user just have to click on the first field to apply the script.
Thanks for your help.
Copy link to clipboard
Copied
Well actually, my idea was to use a value related event, so the update was automatic. For example a custom calculation script. Or plutting a WillCommit keystroke script on the checkbox.
Copy link to clipboard
Copied
"Final datas are in the xfdf....
The script modify the behaviour of a field in a certain one (data) has a specific value."
Then the data is not final!
"The user open the xfdf then it's automatically importing it on the pdf file.
I want to erase a text field (data) if an element is checked (data)."
Set the text field blank in the XFDF.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now