Copy link to clipboard
Copied
I'm creating a pdf where I collect business phone numbers and extensions (if applicable) in a field "BusinessPhone" and a field "BusinessExt", then later in the document the two may get combined into "BusinessNumber" if there is anything in the BusinessExt field.
On Blur for Business Phone I have:
this.getField("BusinessNumber").value = event.target.value;
On Blur for BusinessExt I have:
if ((event.target.value) !== "") {
this.getField("BusinessNumber").value = this.getField("BusinessPhone").valueAsString + " ext. " + this.getField("BusinessExt").valueAsString;
} else {
this.getField("BusinessNumber").value = this.getField("BusinessPhone").valueAsString;
}
Those work for me, but I am having issues with the format of BusinessNumber. If it is just the BusinessPhone value I want it to show as (999) 999-9999 and if it is BusinessPhone + BusinessExt I want it to show as (999) 999-9999 ext. [as many numbers as are filled in for the extension].
The phone number may be entered with or without () or - so I want to make all phone numbers look uniform. I use the format Special > Phone Number on all other phone number fields, and would like this one to look the same. I'm not very strong in javascript, and have been able to google my situation to learn most of what I want to do, but this one keeps putting me into a dead end.
I'm guessing there is something I can put in Custom Formatting but have not yet found anything that works for me. I appreciate any advice you can give. Thank you!
Copy link to clipboard
Copied
Remove all of your scripts (and field format for "BusinessNumber") then use this script as custom calculation script of "BusinessNumber" field:
var bPhone = this.getField("BusinessPhone").valueAsString;
var bExt = this.getField("BusinessExt").valueAsString;
var bPhoneNum = "";
var bExtNum = "";
if(bPhone !== "")
bPhoneNum = util.printx("(999) 999-9999",bPhone);
if(bExt !== "" && bPhone !== "")
bExtNum = "ext."+bExt;
event.value = bPhoneNum+bExtNum;
Copy link to clipboard
Copied
Remove all of your scripts (and field format for "BusinessNumber") then use this script as custom calculation script of "BusinessNumber" field:
var bPhone = this.getField("BusinessPhone").valueAsString;
var bExt = this.getField("BusinessExt").valueAsString;
var bPhoneNum = "";
var bExtNum = "";
if(bPhone !== "")
bPhoneNum = util.printx("(999) 999-9999",bPhone);
if(bExt !== "" && bPhone !== "")
bExtNum = "ext."+bExt;
event.value = bPhoneNum+bExtNum;
Copy link to clipboard
Copied
Thank you so much! This did exactly what I wanted!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now