Copy link to clipboard
Copied
Hello
I have created a fillable form in acrobat DC, I have imported data into it (all works fine).
What I need to do;
I need to create a rule for the imported or merged text in the text field (a bit like mail merge rules in MS word).
For example, if the imported text in the text box is "Shoes" I want it to replace the displayed or imported text "Shoes" with "Shop"
I have tried adding string.replace in the custom calculation script but cannot get it to work.
Can anyone please help
Thank you
Copy link to clipboard
Copied
If you want to change text in place in the field, at the time the text is entered, the best method is to use the Will Commit event. this event is triggered by data being committed to the field, but right before it happens.
To do this, enter this code into the Custom Keystroke:
if(event.willCommit)
{
switch(event.value)
{
case "Shoes":
event.value = "Shop";
break;
case "...":
event.value = "... next replacement";
break;
}
}
If you want the actual text to remain the same, but the display value to change, then use these same code without the initial if(event.willCommit) in a custom Format script.
If the replacement text is part of a larger phrase, and not the whole value in the field, you'll need to use the replace function instead of the switch statement I've shown here
Copy link to clipboard
Copied
Hello,
May I first thank you for taking the time to reply, very much appreciated.
I can report partial success!!
I have followed your directions, if I paste the code into either the "Custom Keystoke" or "Custom Format Script" boxes in "Properties//, nothing happens. If I remove "if(event.willCommit)" and paste in either of the above boxes it works and replaces "Shoes" with "Shop" exactly as expected.
I also tried adding an alternative if the value was not Shoes, ("Not Shoes",(trying to replicate an IF statement , if this, enter that, if not enter other))
I have tried this several times and cannot get it to work with the if part, could I please ask if you can suggest why I cannot get this part to work or perhaps an alternative method.
Thank you again for your help and assistance.
Copy link to clipboard
Copied
I would have to see the code your using. I just tested the script from my previous post and it works without a hitch in the custom keystroke event. And as I indicated in my previous post, the "event.willCommit" property is not used in the Format event, but it is necessary in the keystroke.
If you want other word replacements, then add them to the switch statement as new cases.
Paste your code in to your next response and I can show you how to modify it to work correctly.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more