function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
anjuanju 

Can anybody help me to resovle issue in this visualforce code?

<apex:page standardController="My_Object__c" > 
  <h1>Testing</h1>
  <br/>
    <apex:pageBlock> 
   <apex:form>
     Name &nbsp; <apex:inputField value="{!My_Object__c.Name}" required="true"></apex:inputField>
     <br/>
     DOB <apex:inputField value="{!My_Object__c.Date_of_Birth__c}"></apex:inputField>
       <br/>
     Test Text &nbsp; <apex:inputText value="{!My_Object__c.Note__c}" required="true" ></apex:inputText> 
     <br/>
     <apex:commandButton action="{!save}" value="Save"></apex:commandButton> 
  </apex:form>
</apex:pageBlock>
</apex:page>
 
The highlighted code is not working. In my visual force page 'Test Text' is not displaying as required and I can save without entering any value.
In object 'Note__c' is required field.
 
Can anybody tell me what is wrong in this code?
JimRaeJimRae
Why are you using inputText on that field and inputField on the others?  if the field exists on the object, you should use inputfield.  Then it will follow the rules for that object, including is required.
 
Jim
jwetzlerjwetzler
Yes you should be using inputField.  If it's not styled the way you like you can use the style or styleClass attribute to resize it.

And also read this post, for information about requiredness.
anjuanju
I would like to go with inputText for some custom validation. I know inputField will work properly. But why the the required mark is not displaying for inputText? Then what is the use of 'required' attribute in inputText component? Is there is any other standard way to make the inputText as required other than 'required' attribute?
mtbclimbermtbclimber
Only inputField is currently specified to surface the requiredness indicator. If you'd like to see this on other input components, please log an idea on the idea exchange (click on the ideas tab above).  Setting the value of required will make it impossible to submit the form without providing a value.  You may not be seeing the error message, however if you are not including the apex : pageMessages component in your page.
Sam.arjSam.arj

This is true however the error message shown in this case is not user friendly?

 

Is there any way to customize the message shown to user?

 

 

   j_id0:SiteTemplate:j_id17:ContactBlock:j_id52:j_id53:FirstName: Validation Error: Value is required.