Copy link to clipboard
Copied
I have a custom javascript code in over 200 text fields and I need the same line edited in all of them. Is it possible to do a search and replace instead of manually going in and editing each one?
I'm going to need to change the
color.yellowto another color. (By the way, is it possible to spec hex colors or RGB colors here? I'd actually like to do a beige or tan color. I tried "tan" or "beige" and it didn't work)
// If field is blank, display this text and background color
if (!event.value) {
event.target.fillColor = color.yellow;
event.value = "PROMPT TEXT"
} else {
if (event.value) {
event.target.fillColor = color.transparent;
}
}
Copy link to clipboard
Copied
Let this be a lesson for the future. If you use the same code in multiple places you should put it in a doc-level function and then call that function from all of those places. Then editing it in one spot will affect all of them.
You now have a problem because editing the entire code in the file using search & replace is not a good idea and can cause it to become seriously corrupt. I recommend you switch to using the function approach now. As mentioned, you can use a loop to iterate over all of these fields and use the setAction method to replace the current action with a new one. The only problematic bit might be to create the list of fields to run it on, and also to specify a different text for each one (assuming you don't to use the same text for all of them). You can do that by passing this text as a variable to your function.
Copy link to clipboard
Copied
For hex code you can use them like this:
example: beige hex code F2E7BF = RGB 242 231 191 you divide that by 255 so code would be
["RGB", 0.94, 0.90, 0.74] or if it's easier for you you can use like this ["RGB", 242/255, 231/255, 191/255]
About scripts, there is a way lets say you have 200 text fields, you can use 'setAction' to replace codes in all text fields in the file but you will need custom made script for that.
On the other hand, code you posted is not well written, when field is empty fill color will be yellow and value will be 'PROMPT TEXT', now second part of code kick in and overwrite yellow color with transparent because field is no longer empty so what is point of set it to yellow?
Copy link to clipboard
Copied
Thank you, Nesa for explaining that decimals are needed or fractions. That's new to me. I'll figure that and go.
To clarify, I put "PROMPT TEXT" in my example as an example. There are many different kinds of entries for this form so that was a universal example (I should have put it in brackets and explained that it's a sample text).
The point of this exercise is that the client wanted colors to highlight a field so that the user has a visual flag that something is needed. So when the field doesn't have any info, this prompt shows up with a highlight color. Then when they add the proper info, the highlight goes away.
Copy link to clipboard
Copied
It doesn't matter what text it is when field is empty it will automatically start second part of the code and overwrite first part so teoretically you can't have empty field and so there is no point of setting it that way, you need to rewrite code to allow higlight color and default text.
Copy link to clipboard
Copied
Let this be a lesson for the future. If you use the same code in multiple places you should put it in a doc-level function and then call that function from all of those places. Then editing it in one spot will affect all of them.
You now have a problem because editing the entire code in the file using search & replace is not a good idea and can cause it to become seriously corrupt. I recommend you switch to using the function approach now. As mentioned, you can use a loop to iterate over all of these fields and use the setAction method to replace the current action with a new one. The only problematic bit might be to create the list of fields to run it on, and also to specify a different text for each one (assuming you don't to use the same text for all of them). You can do that by passing this text as a variable to your function.
Copy link to clipboard
Copied
Thanks, Try. I can see now that I created something that is complicated in terms of updating. I'll note this for future reference. As a medium-low-level user as I am, I appreciate your top-level expertise.
I did use Nesa's info to go in and edit all the fields. It took half an hour, so I got it done. Fortunately one of my favorite features of Acrobat is that the Text Field Properties stays open for editing multiple fields individually. Otherwise this would have taken twice as long.
Copy link to clipboard
Copied
In addition to try67's post:
A good practice is to set the color as a variable in the doc level document startup script, so you just need to edit the variable for further changes.
var myCustomColor = color.yellow;
Copy link to clipboard
Copied
Definitely. I live by style sheets in InDesign and in webwork, so implementing them here would make sense.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more