force:inputField component is used to display fields of a particular sObject with the appropriate type. In other words, we don’t have to explicitly specify the type of the field. The component automatically renders the type.
For example: If the type of the field is date, then displays the Data Picker. Similarly if it is picklist, then a dropdown appears.
Consider the following code of force:inputField :
Component Code
Controller Code
Apex Code
Note:
- In the above component, we used this with value attribute only. The component renders the type as text input for LastName, and picklist for the CleanStatus field.
- This component doesn’t use the lightning Design System styling. Use lightning:input if you want an input field that inherits the Lightning Design System styling.
Output:
Try demo:
For more details refer to
https://developer.salesforce.com/docs/component-library/bundle/force:inputField/specification