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
lakshman.mattilakshman.matti 

Enabling Button when check box is checked.

Hi Everyone,

I have a button initially, it is disable(i.e not able to click.).
i want to enable it when if any one of the check box is checked.
here is my check box code.and button code
<apex:column headerValue="Select" style="text-align: center"> 
                        <apex:inputCheckbox id="isCheckBox" style="opacity:{!w2.isPartOrderabilityStatusCode};" value="{!w2.isCheckBox}" >
                            <apex:actionSupport event="onclick" action="{!checkBoxStaus}" reRender="pb2"/>
                        </apex:inputCheckBox>
 </apex:column>
<apex:commandButton value="Add Selected"  action="{!selectRecords}" id="sparebtn" reRender="frm">
                    <apex:actionSupport event="onclick" rerender="resultsBlock" status="statusSaveTrip"/>
</apex:commandButton>

Thanks
Lakshminarayana
 
SF AdminSF Admin
use disabled= "{!(if(Your condition, true, false))}" withinn apex:commandbutton
William LópezWilliam López
Hello,

For that you will need to change a variable in the controller that manage the visibility. 

This variable need to be set to true when any of the checkbox its selected.

Then using a rerender you can display or not the button based on this variable. 

Small demo, I will sleep the columns and output panel, but form the logic you had there is should be a component with id pb2 that will be rerendered when checkbox selected.
 
 
<apex:page Controller="Democlass" extensions="">
<apex:form>


                        <apex:inputCheckbox id="isCheckBox" style="opacity:{!w2.isPartOrderabilityStatusCode};" value="{!w2.isCheckBox}" >
                            <apex:actionSupport event="onclick" action="{!checkBoxStaus}" reRender="pb2"/>
                        </apex:inputCheckBox>

                            

<apex:commandButton value="Add Selected"    rendered="{!(if(isButtonValid==true, true, false))}" action="{!selectRecords}" id="sparebtn" reRender="frm">

                    <apex:actionSupport event="onclick" rerender="resultsBlock" status="statusSaveTrip"/>
</apex:commandButton>

</apex:form>
</apex:page>

The class (several variables missing but you should get the idea)

Public class Democlass{

    public boolean isButtonValid{get;set;}

    public pagereference  checkBoxStaus() {
        // add more logic here like validate all checkboxes to see if any it's checked
        isButtonValid = true;
        return null;
    }
}

I hope it helps, let me know how it goes,

Bill