Hey guys look at my scenario I have a stages(picklist field) in custom object. Requirement is i have to enable my save button only when the stage is 'completed' if the stage is other than 'completed' then only save&new button should be active, how to achieve this.
2 Answers
In your Controller you can create a property that indicates if the picklist should be enabled.
public boolean stagesDisabled {
get {
// Replace stage__c with the correct custom object field reference
return myCustomObject.stage__c != 'completed';
}
}
Then, in your Visualforce page you bind this to your commandButtons disabled property.
<apex:commandButton action="{!someAction}" value="Save&new" disabled="{!stagesDisabled}" />
Adding to Daniel's answer, in case you need this to work on a standard page layout:
- you could use recordtypes (workflow to change the recordtype on status change, assign a different page layout (without the button) to that recordtype
- or use the javascript solution described here: http://www.tehnrd.com/show-and-hide-buttons-on-page-layouts/