Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I have created a input text field and want to make this field required and I did it through required attribute. I also want to put red vertical bar in front of text field which is required indicator in salesforce. I did follow code but red bar is not showing -

            <div class="requiredInput">
                <div class="requiredBlock"></div>
                <apex:inputText value="{!name}" label="Name on Card" required="true"/>
            </div>

How do I get the red bar to display?

share|improve this question
add comment

3 Answers 3

up vote 6 down vote accepted

You can "simulate" the redbar like this:

<apex:pageBlock >
    <apex:pageBlockSection>
        <apex:pageBlockSectionItem>
            <apex:outputPanel>
                <div class="requiredInput">
                    <div class="requiredBlock"></div>
                    <apex:inputText value="{!numberOfRowToRemove}"/>
                </div>
            </apex:outputPanel>
        </apex:pageBlockSectionItem>
    </apex:pageBlockSection>
</apex:pageBlock>
share|improve this answer
    
In what way does this simulate the red bar? –  Jeremy Nottingham Dec 16 '12 at 18:14
1  
It will show the red vertical bar near your input field. The real verification must be done by yourself in apex or javascript. –  mast0r Dec 16 '12 at 18:20
1  
I have done the same thing but bar is not coming as i have shown in my code above –  Pramod Kumar Dec 17 '12 at 5:59
    
Sorry, just updated my code. It works now. –  mast0r Dec 17 '12 at 7:31
add comment

It is because you are using inputText. The red bar doesn't come with inputText. You might want to consider inputField to get the bar if the field is an sObject field.

See Visualforce markup used to display a required password field, with field type "password".

share|improve this answer
    
Actually this "name" field is not a sObject field. It only available in controller not in Object that's why i didn't use inputField. –  Pramod Kumar Dec 16 '12 at 17:06
add comment

Finally i have find out the solution.

            <apex:pageBlockSectionItem >
                <apex:outputLabel value="Name on Card" />
                <apex:outputPanel >
                    <div class="requiredInput">
                        <div class="requiredBlock"></div>
                        <apex:inputText value="{!name}" label="Name on Card"                     
                        required="true"/>
                    </div>
                </apex:outputPanel>
            </apex:pageBlockSectionItem>

above code must be wrapped under apex:pageBlockSectionItem tag.

share|improve this answer
    
Isn't it the same with my code? –  mast0r Dec 17 '12 at 9:22
    
yes its same... i don't know how did i missed it. thanks –  Pramod Kumar Dec 17 '12 at 9:24
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.