Lightning Experience, Experience Builder Sites, Salesforce Mobile App, Lightning Out (Beta), Standalone Lightning App
A lightning:inputName component is a name compound field represented by HTML input elements of type text. The Salutation field is a dropdown menu that accepts an array of label-value pairs.
By default, lightning:inputName displays Salutation, First Name, and Last Name fields. Use the fieldsToDisplay attribute to specify a different list of fields to display. The component supports these field names.
firstName
lastName
middleName
informalName
suffix
salutation
To provide initial values for fields, specify the field names as attributes in the component. Use the options attribute to specify the values to display in the Salutation dropdown menu.
This example creates a simple input name field, consisting of just the First Name and Last Name fields, without specifying initial values. The rendered fields display default placeholder text.
This example creates an input name field that specifies values for first name, middle name, last name, informal name, and suffix. The Salutation dropdown menu is set to display “Mr.” by default. The fieldsToDisplay attribute determines which fields are rendered. Although all possible fields are specified inside the component, only the First Name and Last Name display.
When you set required="true", a red asterisk is displayed on the Last Name field to indicate that it’s required. An error message is displayed below the Last Name field if a user interacted with it and left it blank. The required attribute is not enforced and you must validate it before submitting a form that contains a name compound field.
Let’s say you have a lightning:button component that calls the handleClick controller action. You can display the error message when a user clicks the button without providing a value for the Last Name field.
1({2 handleClick: function(cmp, event){3 var name = cmp.find("myname");4 var isValid = name.checkValidity();5 if(isValid){6 alert("Creating new contact for " + name.get("v.lastName"));7}else{8 name.showHelpMessageIfInvalid();9}10},11});
To check the validity states of an input, use the validity attribute, which is based on the ValidityState object of the Constraint Validation API. You can access the validity states in your client-side controller. This validity attribute returns an object with boolean properties.
You can override the default message by providing your own value for messageWhenValueMissing.
To programmatically display error messages on invalid fields, use the reportValidity() method. For custom validity error messages, display the message using setCustomValidityForField() and reportValidity(). For more information, see the lightning:input documentation.
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, your org’s locale setting determines the order of the name fields.
For example, if you select “Japanese (Japan)” in the Locale field, lightning:inputName uses ja-JP as the locale.
The body of the component. In markup, this is everything in the body of the tag.
Aura.Component[]
class
A CSS class for the outer element, in addition to the component's base classes.
String
disabled
Specifies whether the compound field should be disabled. Disabled fields are grayed out and not clickable. This value defaults to false.
Boolean
fieldLevelHelp
Help text detailing the purpose and function of name compound field.
String
fieldsToDisplay
List of fields to be displayed on the component. This value defaults to ['firstName', 'salutation', 'lastName']. Other field values include middleName, informalName, suffix.
List
['firstName', 'salutation', 'lastName']
firstName
Displays the First Name field.
String
informalName
Displays the Informal Name field.
String
label
Text label for the compound field.
String
lastName
Displays the Last Name field. This field must be specified if you set required to true.
String
locale
Specifies the locale used to determine the layout of the name fields. This value defaults to en-US.
String
middleName
Displays the Middle Name field.
String
onblur
The action triggered when the input releases focus.
Aura.Action
onchange
The action triggered when the value changes.
Aura.Action
onfocus
The action triggered when the input receives focus.
Aura.Action
options
Defines a list of salutation options, such as Dr. or Mrs., as an array of label-value pairs.
List
readonly
Specifies whether the compound field is read-only. This value defaults to false.
Boolean
required
Specifies whether the compound field must be filled out. A red asterisk is displayed on the Last Name field. An error message is displayed if a user interacts with the Last Name field and does not provide a value. This value defaults to false.
Boolean
salutation
Displays the Salutation field as a dropdown menu. Use the options attribute to provide salutations in an array of label-value pairs.
String
suffix
Displays the Suffix field.
String
title
Displays tooltip text when the mouse moves over the element.
String
variant
The variant changes the appearance of the name compound field. Accepted variants include standard, label-hidden, label-inline, and label-stacked. This value defaults to standard. Use label-hidden to hide the label but make it available to assistive technology. Use label-inline to horizontally align the label and name fields. Use label-stacked to place the label above the name fields.
String
Methods
Name
Description
Argument Name
Argument Type
Argument Description
checkValidity
Returns the valid property value (Boolean) on the ValidityState object to indicate whether input name fields have validity errors.
reportValidity
Display error messages if an input name field is invalid.
setCustomValidityForField
Sets a custom error message to be displayed for the input name fields when the input value is submitted.
message
String
The string that describes the error. If message is an empty string, the error message is reset.
fieldName
String
The name of the input name field.
showHelpMessageIfInvalid
Shows the help message if input name fields are in an invalid state.