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
Varun99Varun99 

Enable custom button in vf page based on pick list values

Hi,

 

 I hvave designed a VF page same as Edit opportunity page. And i have a button called "CBTN" , How to enable command button when select opportunity stage "Closed-Won" ohter wise it will disable mode.

 

My Page override with opportunity detail page edit button already record saved with stage name "Closed-Won" buttonautomatic enable when page load? 

I am using java script for button enable.but stage has action support for automatic probality how to include artomatic probablity also in java script.

 

Below is my script

<apex:includeScript value="{!URLFOR($Resource.Jqueryui18, 'js/jquery-1.7.1.min.js')}" />
<apex:includeScript value="{!URLFOR($Resource.Jqueryui18, 'js/jquery-ui-1.8.18.custom.min.js')}" />
<apex:stylesheet value="{!URLFOR($Resource.Jqueryui18,'css/smoothness/jquery-ui-1.8.18.custom.css')}"/>
<script type="text/javascript">
var $ = jQuery.noConflict();
$(document).ready(function()
{
//alert('gdhgh');
$("input[id$=':cbtn']").attr("disabled", "disabled");
});
function checkEnableSubmit(value)
{
//alert('wwwwwwww');
if (value=='6. Started Trading - Closed Won')
{
//alert('ddddddd');
$("input[id$=':cbtn']").removeAttr("disabled");
$("input[id$=':cbtn']").css("color","Black");
$("input[id$=':cbtn']").css("Cursor","pointer");
}
else
{
$("input[id$=':cbtn']").attr("disabled", "disabled");
$("input[id$=':cbtn']").css("color","gray");
}
}
</script>

 

 

Can any one help me? how to write java script for button enable and automatic  probability when stage select.

 

 

Thank you

 

 

 

 

<apex:actionregion >
<apex:inputField value="{!opp.stagename}"  onchage=" checkEnableSubmit()"> 
<apex:actionSupport onchage=" " /> </apex:inputfield>
</apex:actionregion>

 

 

 <apex:inputField value="{!opp.Probability}" id="probability"></apex:inputfield>

 

 

Yoganand GadekarYoganand Gadekar

If your requirement is to enable button on stage change to Closed-Won.

Follow following approach:

 

1. Call js onchane on you field stage in vf page.

2. Use disable attribute of commandbutton bind its value witha boolean variable in controller

2.Check for stage value in js, if your stage is Closed-Won call action function

(You should define action in your vf page somewhere.)

3.From actionfunction yopu should calla controller methode where your boolean varaible for command button disable gets changed and  probability gets calculated for new value. 

 

Visit this example to know more about actionfunction Action function use example

 

 

(put this new value in your probality varaiable binded on vf page)

4. write reRender in your action function that will refresh your page section which displays probability and button.

 

Thanks,

Salesforce knowldege sharing at 

Cloudforce4u

Karthikeyan JayabalKarthikeyan Jayabal

Below is a sample code: (meets the button disabling functionality & not probability population)

NOT Javascript, BUT without any controller code

 

<apex:page standardController="Opportunity">
<apex:form >
    <apex:pageBlock id="pBlock" title="New Opportunity" mode="edit">
        <apex:pageBlockButtons >
            <apex:commandButton value="Save" action="{!save}"/>
            <apex:commandButton value="Cancel" action="{!cancel}"/>
            <apex:commandButton value="Won Notes" disabled="{!NOT(opportunity.StageName='Closed Won')}"/>
            <apex:actionStatus id="rStatus" startText="Refreshing..."/>
        </apex:pageBlockButtons>
        <apex:pageBlockSection columns="1">
            <apex:pageBlockSectionItem >
                <apex:outputLabel value="Stage"/>
                <apex:actionRegion >
                <apex:inputField value="{!opportunity.StageName}">
                    <apex:actionSupport event="onchange" reRender="pBlock" status="rStatus"/>
                </apex:inputField>
            </apex:actionRegion>
            </apex:pageBlockSectionItem>
            <apex:inputField value="{!opportunity.Probability}"/>
            <apex:inputField value="{!opportunity.Name}"/>
            <apex:inputField value="{!opportunity.CloseDate}"/>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:form>
</apex:page>