You need to sign in to do that
Don't have an account?
Display formatted phone number in pdf
I created a visualforce page that displays the opportunity owner's phone number with the standard U.S. formatting "(555) 555-5555". Since the phone number is retrieved from the database unformatted (e.g. "5555555555"), I uploaded the jquery 1.9.1 library as a static resource and added a script to format the number as shown below. It works perfectly, however, when I try to render the page as pdf it no longer displays with the formatting. Is there any way to display it without having to create a controller extension? And if not, what is the simplest controller extension that would format the phone number?
<apex:page standardController="Quote" renderAs="pdf">
<head>
<apex:includeScript value="{!$Resource.jquery}"/>
<script>
$(document).ready(function() {
// Attach masks to correct input fields
$(".phone").text(function(i, text) {
text = text.replace(/(\d\d\d)(\d\d\d)(\d\d\d\d)/, "($1) $2-$3");
return text;
});
});
</script>
</head>
<apex:outputText styleClass="phone" value="{!Quote.Opportunity.Owner.Phone}" />
</apex:page>
Hi Manuel,
The quick solution that I can think of now is, why don't you change and save the phone number in the Apex object itself. You can use the string function .replace() in the apex class to format accordingly.
Best,
Ankit
P.S.: Mark it as a solution if it helped you.
All Answers
Hi Manuel,
The quick solution that I can think of now is, why don't you change and save the phone number in the Apex object itself. You can use the string function .replace() in the apex class to format accordingly.
Best,
Ankit
P.S.: Mark it as a solution if it helped you.
Thanks Ankit - I ended up creating a Quote extension class and formatted the phone number as shown below. It's not a pretty solution but it works.