Friday 7 September 2012

Show Field Labels - Visualforce


Visualforce does a lot of work behind the scenes, binding the input field to a field on a new record. It can do more, such as automatically showing the field label (much like<apex:outputField> in Tutorial #5: Using Standard User Interface Components), as well as automatically changing the input element to match the data type (for example, showing a picklist instead of an input box).
Modify the contents of the <apex:form> element so that it reads as follows:
<apex:form>
    <apex:pageBlock>
        <apex:pageBlockSection> <apex:inputField value="{!account.name}"/>
            <apex:inputField value="{!account.industry}"/> <apex:commandButton action="{!save}" value="Save!"/>
        </apex:pageBlockSection>
    </apex:pageBlock> </apex:form>
By encapsulating the input fields within <apex:pageBlock> and <apex:pageBlockSection> components, Visualforce automatically inserts field labels (“Account Name”, “Industry”) as well as indicators of whether values are required for the fields, all using the platform styles.

Form with a Field Label

No comments:

Post a Comment