Discussions
- General Development
- Schema Development
- Apex Code Development
- Visualforce Development
- Formulas & Validation Rules
- Security
- Mobile
- Force.com Sites & Site.com
- Chatter Development
- Java Development
- .NET Development
- Perl, PHP, Python & Ruby
- Desktop Integration
- APIs and Integrations
- Visual Workflow
- Apple, Mac and OS X
- VB and Office Development
- AppExchange Directory & Packaging
- Salesforce Labs & Open Source Projects
- Other Salesforce Applications
- Jobs Board
- Force.com Discussion Boards
- :
- Developer Boards for Force.com and Database.com
- :
- Visualforce Development
- :
- required attribute on input controls
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
required attribute on input controls
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
05-14-2008 02:32 PM - edited 05-14-2008 04:37 PM
For example:
<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
Re: required attribute on input controls
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
05-14-2008 02:59 PM
basicaly the inputField* methods know what their data type is down to the database level, with requiredness
the inputText* input methods do not.
Application Architect
Check out the developer documentation | Got an idea? | Vote for this Idea!
Re: required attribute on input controls
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
05-14-2008 03:54 PM
<apex:pageBlockSectionItem>
<apex:outputLabel value="Subject" for="case_subject"/>
<apex:outputPanel styleClass="requiredInput" layout="block">
<apex:outputPanel styleClass="requiredBlock" layout="block"/>
<apex:inputText id="case_subject" value="{!case.Subject}"/>
<apex:outputPanel styleClass="errorMsg" layout="block" rendered="{!errorNoSubject}">
<strong>Error:</strong> You must provide a subject
</apex:outputPanel>
</apex:outputPanel>
</apex:pageBlockSectionItem>
Please vote for my idea: better tab order control on Visualforce pages.
http://ideas.salesforce.com/article/show/10089079/Tab_order_or_Visualforce_page
Re: required attribute on input controls
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
05-14-2008 04:36 PM
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.
Re: required attribute on input controls
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
05-15-2008 07:15 PM
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.
Re: required attribute on input controls
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
05-16-2008 04:54 AM
For example:
<apex:page standardController="Case">
<apex:form>
<apex:pageBlock title="Case Comment 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="Description" for="case__description"/>
<apex:inputField required="true" value="{!case.Description}"/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
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.
Re: required attribute on input controls
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
05-16-2008 10:13 AM
<apex:page standardController="case">
<apex:form>
<apex:pageBlock>
<apex:pageBlockSection>
<apex:inputField value="{!case.description}" required="true" style="width:500px; height:200px"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>You can adjust the width and height accordingly, I was just throwing some values in.
Re: required attribute on input controls
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
05-16-2008 10:34 AM - edited 05-16-2008 10:35 AM
<apex:page standardController="Case">
<style>
.width {width: 800px}
</style>
<apex:form>
<apex:pageBlock title="Case Comment 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="Description" for="case__description"/>
<apex:inputField required="true" value="{!case.Description}" styleClass="width"/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>Edit: looks like it was already answered above.
Message Edited by TehNrd on 05-16-2008 10:35 AM
Re: required attribute on input controls
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-03-2008 02:27 AM
Vote for my ideas

