You need to sign in to do that
Don't have an account?
How to avoid page refresh on validation
Currently, with the code below, when a user clicks on the OK button, if there is a validation error the page refreshes, if not the record saves successfully and the user is redirected to another page. How can I avoid the page refresh without losing the validation message displaying on the page?.
Or, how can I force the user to select an option (this field is a picklist) to be able to click on the OK button, this would avoid having to deal with the validation.
VF:
<apex:message/>
<apex:inputField id="reasonres" required="true" value="{!case.Reason_Resolved__c}" />
<apex:commandButton action="{!closecase}" value="OK" />
controller:
public PageReference closecase() {
caseobj.status='closed';
if( caseobj.Reason_Resolved__c == null ) {
caseobj.Reason_Resolved__c.addError('Please select a close reason');
return null;
}else{
caseController.save();
return Page.MySupport;}
}
Thanks.
<apex:message immediate = "true">
That will execute the error message or a validation rule voilation first before getting refresh.
If this answers your question please make this as solution.
Hi
you already given "required" in put field. the picklist is "--NONE" treated as blank value.
salesforce itself gives standard validation.
why using add error message ?
Hi Sivaext,
I was trying many ways to do this, but regardless of using the standard validation or a custom validation, the page always refreshes if any type of validation is triggered. :(
k
this the situation i came across and got success with that
the thing is
<apex:pageMessage id="msg1"/>
in the command button i am rendering this message
<apex:commandButton action={!Save} reRender="msg" immediate="true"/>
This is working fine by overcomming most of the errors i came across
Try it