Displaying the Required Red Bar for a Control

November 16th, 2008

My Visualforce page uses a number of outputLabels and selectLists to create the functionality below. Setting the selectList’s required attribute makes the select’s value required but does not, by design, display the red bar next to the label. This is perfect is it does not lock developers into Salesforce.com’s look and feel. However, to actually display the required red bar, you have to add some extra code.

red-bar

1
2
3
4
5
6
7
8
9
10
11
 
<apex:pageBlockSectionItem >
    <apex:outputLabel value="Category 1" for="cbxlevel1"/>
    <apex:outputPanel styleClass="requiredInput" layout="block">
    <apex:outputPanel styleClass="requiredBlock" layout="block"/>
    <apex:selectList value="{!selectedLevel1}" id="cbxlevel1" size="1" required="true">
        <apex:selectOptions value="{!level1items}"/>
        <apex:actionSupport event="onchange" rerender="cbxlevel2"/>
    </apex:selectList>
    </apex:outputPanel>
</apex:pageBlockSectionItem>
VN:F [1.9.3_1094]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.3_1094]
Rating: 0 (from 0 votes)
Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay

Categories: Code Sample, Salesforce, Visualforce

Leave a comment

Comments Feed3 Comments

  1. RM

    Great Tip, Thanks for sharing.
    Exactly what I was looking for.

    FYI.. Why do u make emails required, it is hard to post a comment.

    VA:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.3_1094]
    Rating: 0 (from 0 votes)
  2. nicole

    thank you for this interesting post.

    VA:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.3_1094]
    Rating: 0 (from 0 votes)
  3. Dependent Multilevel Selectlists | Jeff Douglas - Technology, Coding and Bears... OH MY!

    [...] had a number of follow-up emails regarding the code I used for my Displaying the Required Red Bar for a Control post. We assign a number of values to an Opportunity based upon a hierarchy modeled by 3 objects [...]

Leave a comment

Feed

http://blog.jeffdouglas.com / Displaying the Required Red Bar for a Control

WordPress Appliance - Powered by TurnKey Linux