I want to make an inputText field's attribute required="true" on the VF page and display the error message : Error: You must enter a value (Note: I do not want to use an InputField here)
When I click on the submit button, this doesn't show me the inline error message.
Please see the below code, and can some one explain what am I doing wrong here?
<apex:page sidebar="false" showHeader="false" id="page" standardController="Case" extensions="MyControllerExt">
<div>
<apex:form styleClass="form-horizontal" id="form">
<div class="requiredInput">
<div class="requiredBlock"></div>
<apex:inputText value="{!myCustomVar}" id="LastName" label="LastName" required="true" />
</div>
<!-- Submit From -->
<apex:commandButton id="btn2" styleclass="btn btn-lg btn detail" rerender="form" value="Submit" action="{!submitAction}" />
</apex:form>
</div>
And this is what the document say about the required true attribute;
required -> Boolean -> 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.
Best Answer
You seem to be missing
<apex:messages/>
in your vf page. By definition, it says:I verified this, and once you add the tag, it works fine. However you will still need to address the styling as @sfdcfox mentioned, it does not really render as expected when required=true.