Formatted Name

lightning:formattedName

Displays a formatted name that can include a salutation and suffix. This component requires API version 42.0 and later.

For Aura components only. For LWC development, use lightning-formatted-name.

For Use In

Lightning Experience, Experience Builder Sites, Salesforce Mobile App, Lightning Out (Beta), Standalone Lightning App, Mobile Offline

A lightning:formattedName component displays formatted names in a given format and order. The locale set in the app’s user preferences determines how names are formatted and the order they are presented.

This example displays “Mr. John Middleton Doe The 3rd Jo” based on the default English United States locale with the long format.

1<aura:component>
2  <lightning:formattedName
3    firstName="John"
4    middleName="Middleton"
5    lastName="Doe"
6    informalName="Jo"
7    suffix="The 3rd"
8    salutation="Mr."
9  />
10</aura:component>

The format attribute determines the length of the name to be displayed.

FormatDescriptionExample
shortDisplays the first name and last name only.John Doe
mediumDisplays the first name, middle name, and last name only.John Middleton Doe
long (default)Displays the name including salutation, first name, middle name, last name, suffix, informal name.Mr. John Middleton Doe The 3rd Jo

For more information on supported locales, see Supported Locales in the Salesforce Help.

To create a form that takes in user input for names, you can use the lightning:inputName component, which displays a name compound field that supports user input for salutation, suffix, and so on.

Using the Locale Information 

In Lightning Experience, the locale value corresponds to the Locale field on the Language & Time Zone page in the user’s personal settings .

By default, the org’s locale setting determines the order of the name fields. If a user sets their personal locale setting, it overrides the org’s locale setting.

For example, if you select “Japanese (Japan)” in the Locale field, lightning:inputName uses ja-JP as the locale.

To enable your component to override the user’s personal locale setting, set the locale attribute. Specify any locale code from the list of Supported Number, Name, and Address Formats (ICU) .

1<aura:component>
2  <lightning:formattedName
3    firstName="John"
4    middleName="Middleton"
5    lastName="Doe"
6    informalName="Jo"
7    suffix="The 3rd"
8    salutation="Mr."
9    locale="fr-FR"
10  />
11</aura:component>

If you don’t specify the locale attribute, lightning:formattedName defaults to the user’s locale setting in the org.

If you pass in an invalid locale, the component uses en-US. The locale supports both hyphens and underscores, for example, en-US or en_US.

Attributes 

NameDescriptionTypeDefaultRequired
bodyThe body of the component. In markup, this is everything in the body of the tag.Aura.Component[]
classA CSS class for the outer element, in addition to the component's base classes.String
firstNameThe value for the first name.String
formatThe format for which to display the name. Valid values include short, medium, and long. This value defaults to long.String
informalNameThe value for the informal name.String
lastNameThe value for the last name.String
localeSpecifies the locale used to determine the order of name components of the formatted name. This value defaults to en-US.String
middleNameThe value for the middle name.String
salutationThe value for the salutation, such as Dr. or Mrs.String
suffixThe value for the suffix.String
titleDisplays tooltip text when the mouse moves over the element.String