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
Vinay_guptaVinay_gupta 

Disable search button when search button is clicked

Hi All,

Urgent help needed.

I am new to Salesforce and need your guidance to grey out the GO button. When the GO button is clicked, the button immediately greys out and prevent the user from clicking the button multiple times. GO button is calling a method called Search in a custom controller.

<apex:commandButton id="btnGo" value="{!$Label.Go}" action="{!Search}" rerender="searchResults">


Request you to please share your advice if we can grey out the button or put some fancy text that "Search is happening" until the result comes out.


Regards,
Vinay
Best Answer chosen by Vinay_gupta
Abdul KhatriAbdul Khatri
Can you try the below code 
<apex:actionStatus id="disablebtn">
    <apex:facet name="stop">
        <apex:commandButton id="btnGO" value="{!$Label.Go}" action="{!Search}" style="margin-left: 450px"  reRender="searchResults" status="disablebtn" disabled="false"/>
    </apex:facet>    
    <apex:facet name="start">
        <apex:commandButton style="margin-left: 450px" status="disablebtn" value="Searching..." disabled="true"/>
    </apex:facet>
</apex:actionStatus>

 

All Answers

Abdul KhatriAbdul Khatri
Create a property by the name as below or whatever you like on the controller class level
public Boolean disabled { get; set;}
Now make use of the button attribute disabled
<apex:commandButton id="btnGo" value="{!$Label.Go}" action="{!Search}" rerender="searchResults" disabled="{!disabled}">
In the Search Method you can do something like this
public void Search() {

    disabled = true;

    //Your code

}
Vinay_guptaVinay_gupta
Hi Abdul,

Thanks for your Quick reply.
I tried your way but it's not working. It not even showing any result on GO button click.

Can you please suggest me any other way to fix this.?

Regards,
Vinay
 
Abdul KhatriAbdul Khatri
You need to adjust that line as per your need, may be after you return the result
disabled = true;
Vinay_guptaVinay_gupta
Hi Abdul,

I tried it again and GO button is getting disabled permanently. if the user wants to click on GO button again, its greyed out.
Please suggest.

Regards,
Vinay
 
Abdul KhatriAbdul Khatri
Isn't that you wanted. 

Is your Search based on certain criteria, I meant do you have input fields. You can make it enables if someone change the criteria.
 
Vinay_guptaVinay_gupta
Hi Abdul,

I have the below lookup box where I have two search filter. Here the Go button is getting permanently disabled and it does not allow the user to put any value.

Any suggestion?


Search Filter
Abdul KhatriAbdul Khatri
I am not sure why you wanted to greyout the button. Is your search taking long to come back?
Vinay_guptaVinay_gupta
HI Abdul,

Yes, the search is taking the longer time to pull the result. Hence I wanted to grey out the button until the result display in the screen. 
 
The search result comes after running 6-7 SOQL queries. Thus it takes longer time.  Therefore I wanted to restrict the user to not to click again during the search is happening in the background.

I hope you understand my requirement. Kindly suggest me to achieve this easily.



 
Abdul KhatriAbdul Khatri
Can you try the below code 
<apex:actionStatus id="disablebtn">
    <apex:facet name="stop">
        <apex:commandButton id="btnGO" value="{!$Label.Go}" action="{!Search}" style="margin-left: 450px"  reRender="searchResults" status="disablebtn" disabled="false"/>
    </apex:facet>    
    <apex:facet name="start">
        <apex:commandButton style="margin-left: 450px" status="disablebtn" value="Searching..." disabled="true"/>
    </apex:facet>
</apex:actionStatus>

 
This was selected as the best answer
Vinay_guptaVinay_gupta
Hi Abdul,


Thanks, it worked fine!!