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
VisualForceVisualForce 

Problem in required="true"

Hi..

  In my VF page Name field is set required=true. When Name filed is blank I hit the cancel button It shows the validation error message 'Error: You must enter a value'.

    How to avoid it...

My sample code

Page:
<apex:page controller="RequiredTest">
<apex:form >
<apex:pageblock>
<apex:outputlabel value="Name"/>
<apex:inputfield value="{!cus.Name}" required="true"/>
<apex:outputlabel value="Number"/>
<apex:inputfield value="{!cus.No__c}" />
<apex:commandbutton value="Cancel" action="{!cancel}"/>
</apex:pageblock>
</apex:form>
</apex:page>

Controller:
public class RequiredTest
{
Custom__c cus;
public Custom__c getcus()
{
return cus;
}
public pagereference cancel()
{
pagereference can=new pagereference ('500/o'); // Here 500 is my custom object tab url
can.setRedirect(true);
return can;
}
}

 



This is my 100th post
Message Edited by VisualForce on 02-22-2009 10:12 PM
Best Answer chosen by Admin (Salesforce Developers) 
JimRaeJimRae
Put an immediate=true on your cancel commandbutton and the validation won't fire.

All Answers

JimRaeJimRae
Put an immediate=true on your cancel commandbutton and the validation won't fire.
This was selected as the best answer
VisualForceVisualForce

Thanks Jim..

           Its work fine.

I need one additional info from u.

 When I use required="true" for Number field without immediate="true" its also working fine.

Why its working...?

<apex:inputfield value="{!cus.No__c}" required="true" />

JimRaeJimRae

I don't know the answer to that. I have experienced similar inconsistancies.

My solution, using the immediate, seems to take care of it, so I have just used that.

VisualForceVisualForce

Thanks Jim.

 Your solution is very helpful for me...