Newer Version Available
apex:inputField
An HTML input element for a value that corresponds to a field on a Salesforce object. The <apex:inputField> component respects the attributes of the associated field, including whether the field is required or unique, and the user interface widget to display to get input from the user. For example, if the specified <apex:inputField> component is a date field, a calendar input widget is displayed. When used in an <apex:pageBlockSection>, <apex:inputField> tags automatically display with their corresponding output label.
Use this component to get user input for a controller method that does not correspond to a field on an sObject. Only <apex:inputfield> and apex:outfield can be used with sObject fields.
- For lookup fields, mouse events fire on both the text box and graphic icon.
- For multi-select picklists, all events fire, but the DOM ID is suffixed with _unselected for the left box, _selected for the right box, and _right_arrow and _left_arrow for the graphic icons.
- For rich text areas, no events fire.
- Read-only fields, and fields for certain Salesforce objects with complex automatic behavior, such as Event.StartDateTime and Event.EndDateTime, don't render as editable when using <apex:inputField>. Use a different input component such as <apex:inputText> instead.
- An <apex:inputField> component for a rich text area field can't be used for image uploads in Site.com sites or Force.com Sites due to security constraints. If you want to enable users to upload image files in either of those contexts, use an <apex:inputFile> component.
- If custom help is defined for the field in Setup, the field must be a child of an <apex:pageBlock> or <apex:pageBlockSection>, and the Salesforce page header must be displayed for the custom help to appear on your Visualforce page. To override the display of custom help, use the <apex:inputField> in the body of an <apex:pageBlockSectionItem>.
This component supports HTML pass-through attributes using the "html-" prefix. Pass-through attributes are attached to the generated <input> tag.
Example
1<!-- For this example to render fully, associate the page
2with a valid account record in the URL.
3For example: https://Salesforce_instance/apex/myPage?id=001D000000IRt53 -->
4
5<apex:page standardController="Account">
6 <apex:form>
7 <apex:pageBlock title="My Content" mode="edit">
8 <apex:pageBlockButtons>
9 <apex:commandButton action="{!save}" value="Save"/>
10 </apex:pageBlockButtons>
11 <apex:pageBlockSection title="My Content Section" columns="2">
12 <apex:inputField value="{!account.name}"/>
13 <apex:inputField value="{!account.site}"/>
14 <apex:inputField value="{!account.type}"/>
15 <apex:inputField value="{!account.accountNumber}"/>
16 </apex:pageBlockSection>
17 </apex:pageBlock>
18 </apex:form>
19</apex:page>Attributes
| Attribute Name | Attribute Type | Description | Required? | API Version | Access |
|---|---|---|---|---|---|
| id | String | An identifier that allows the inputField component to be referenced by other components in the page. | 10.0 | global | |
| ignoreEditPermissionForRendering | Boolean | If set to true, users can edit the field even when the underlying
permission on the object doesn't allow edits. This override affects
all users but is intended to be used only for guest users. This
attribute works only with a custom controller in without sharing
mode. Users must have entity read permissions and field-level security read access for the object. This attribute
bypasses entity edit permissions and field-level security edit
checks, so any form field that uses <apex:inputField> with
this attribute is open for edit. To validate fields or block
edit access when using this attribute, use additional checks in
the page's custom Apex controller.
|
49.0 | global | |
| label | String | A text value that allows you to override the default label that is displayed for the field. You can set label to an empty string to hide the label on forms. Setting it to null is an error. | 23.0 | ||
| list | Object | A list of auto-complete values to be added to an HTML <datalist> block associated
with the input field. The list attribute is specified as either a comma-delimited static string or a Visualforce expression. An expression can resolve to either a comma-delimited string, or a list of objects. List elements can be any data type, as long as that type can be coerced to a string, either as an Apex language feature or via a toString() method. |
29.0 | ||
| onblur | String | The JavaScript invoked if the onblur event occurs--that is, if the focus moves off of the field. | 12.0 | global | |
| onchange | String | The JavaScript invoked if the onchange event occurs--that is, if the user changes the content of the field. | 12.0 | global | |
| onclick | String | The JavaScript invoked if the onclick event occurs--that is, if the user clicks the field. | 12.0 | global | |
| ondblclick | String | The JavaScript invoked if the ondblclick event occurs--that is, if the user clicks the field twice. | 12.0 | global | |
| onfocus | String | The JavaScript invoked if the onfocus event occurs--that is, if the focus is on the field. | 12.0 | global | |
| onkeydown | String | The JavaScript invoked if the onkeydown event occurs--that is, if the user presses a keyboard key. | 12.0 | global | |
| onkeypress | String | The JavaScript invoked if the onkeypress event occurs--that is, if the user presses or holds down a keyboard key. | 12.0 | global | |
| onkeyup | String | The JavaScript invoked if the onkeyup event occurs--that is, if the user releases a keyboard key. | 12.0 | global | |
| onmousedown | String | The JavaScript invoked if the onmousedown event occurs--that is, if the user clicks a mouse button. | 12.0 | global | |
| onmousemove | String | The JavaScript invoked if the onmousemove event occurs--that is, if the user moves the mouse pointer. | 12.0 | global | |
| onmouseout | String | The JavaScript invoked if the onmouseout event occurs--that is, if the user moves the mouse pointer away from the field. | 12.0 | global | |
| onmouseover | String | The JavaScript invoked if the onmouseover event occurs--that is, if the user moves the mouse pointer over the field. | 12.0 | global | |
| onmouseup | String | The JavaScript invoked if the onmouseup event occurs--that is, if the user releases the mouse button. | 12.0 | global | |
| onselect | String | The JavaScript invoked if the onselect event occurs--that is, if the user selects a checkbox associated with this field. | 12.0 | global | |
| rendered | Boolean | A Boolean value that specifies whether the component is rendered on the page. If not specified, this value defaults to true. | 10.0 | global | |
| required | Boolean | A Boolean value that specifies whether this inputField is a
required field. If set to true, the user must specify a value for
this field. If not selected, this value defaults to false. If this input field displays a custom object name, its value can be set to nil and won't be required unless you set this attribute to true. The same doesn't apply to standard object names, which are always required regardless of this attribute. |
10.0 | global | |
| showDatePicker | Boolean | Whether to use the Visualforce date picker for this field, or
suppress it in favor of a browser-based date picker. This attribute only affects date and datetime fields, and activating a browser-based type-appropriate selection widget requires the type attribute be set to one of these date- or time-compatible types:
|
29.0 | ||
| style | String | The CSS style used to display the inputField component. This attribute may not work for all values. If your text requires a class name, use a wrapping span tag. | 12.0 | global | |
| styleClass | String | The CSS style class used to display the inputField component. This attribute may not work for all values. If your text requires a class name, use a wrapping span tag. | 12.0 | global | |
| taborderhint | Integer | A hint to indicate the relative order in which this field is selected compared to other page components when a user presses the Tab key repeatedly. This value must be an integer between 1 and 3276, with component 1 being the first component that is selected when a user presses the Tab key. | 23.0 | ||
| type | String | The HTML5 type attribute
to add to the generated <input> element. Valid type values are:
|
29.0 | ||
| value | Object | An expression that references the Salesforce field to associate
with this inputField. For example, if you want to display an input
field for an account's name field, use value="{!account.name}".
You can't associate an inputField with a formula field of type currency if your organization is using dated exchange rates. |
10.0 | global |