You need to sign in to do that
Don't have an account?

required attribute on input controls
I'm not able to get the required attribute on input controls to correctly display the red bar next to the control.
For example:
If I change inputText to inputField, the control will display properly. From the documentation, it appears to me that this should work with inputText, inputTextarea, etc.
Message Edited by james2000 on 05-14-2008 04:37 PM
For example:
Code:
<apex:page standardController="Case"> <apex:form> <apex:pageBlock title="Case Edit" mode="edit"> <apex:pageBlockButtons> <apex:commandButton action="{!save}" value="Save"></apex:commandButton> <apex:commandButton action="{!cancel}" value="Cancel"></apex:commandButton> </apex:pageBlockButtons> <apex:pageBlockSection title="Case Comments" columns="1"> <apex:pageBlockSectionItem> <apex:outputLabel value="Subject" for="case__subject"/> <apex:inputText required="true" value="{!case.Subject}"/> </apex:pageBlockSectionItem> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
If I change inputText to inputField, the control will display properly. From the documentation, it appears to me that this should work with inputText, inputTextarea, etc.
Message Edited by james2000 on 05-14-2008 04:37 PM
basicaly the inputField* methods know what their data type is down to the database level, with requiredness
the inputText* input methods do not.
A Boolean value that specifies whether this field 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.
I just assumed it would be rendered as a required field. If that's not the behavior, a note in the docs would be helpful.
If you must go with inputText, a view source of a page with a required field shows that you can wrap your inputText with:
<div class="requiredInput"><div class="requiredBlock"></div><apex:inputText...></div>
This must occur within a pageBlock in order for the css to be structured correctly.
However, while this is a solution for what you're trying to do, I don't want to suggest calling into salesforce css styles often because these can and do change. Unless you have a compelling reason not to use inputField, that's what I would suggest.
A couple of side notes about your page. If you're going to use outputLabel (which you should if you are going to use inputText), your "for" attribute should reference the id of the inputText. (I assume you know this since you're even using outputLabel in the first place, but I want to make sure). Better yet though, you can replace that entire pageBlockSectionItem with a call to apex:inputField and we'll take care of the label for you. We'll style it and even translate it based on your language setting.
For example:
Using an inputField for a textarea does show the red bar for a required textarea but the text area is too small and doesn't appear the default size of other SF textarea fields.
You can adjust the width and height accordingly, I was just throwing some values in.
Edit: looks like it was already answered above.
Message Edited by TehNrd on 05-16-2008 10:35 AM