+ Start a Discussion
Jyosi jyosiJyosi jyosi 

Disable button is checkbox is false in wrapper class

Hello Everyone,

I need to disable checkbox when check box is false on  visualforce page I am using wrapper class.
Below is the code

Visualforce page code

<apex:pageBlockSection collapsible="false" title="Rep Downline" rendered="{!initialStep}" columns="1">
             <apex:pageblockTable value="{!contactWrapperList}" var="cont" >
             <apex:column >
              <apex:facet name="header">
              <apex:inputCheckbox onclick="selectAllCheckboxes(this,'inputId')"/>
              </apex:facet>
              <apex:inputCheckbox value="{!cont.Oppflagvalue}" id="inputId" immediate="true" >
               <apex:actionSupport event="onclick" reRender="ButtonId" />
               </apex:inputCheckbox>
               </apex:column>
               <apex:column headerValue="CRD#">
               <apex:outputText value="{!cont.cnt.CRD__c}" />    
               </apex:column>
               <apex:column headerValue="Rep Name">
               <apex:outputText value="{!cont.cnt.Name}" />  
               </apex:column>
                <apex:column headerValue="Downline" id="dsp" >
                <apex:outputField value="{!cont.cnt.Downline__c}" />  
                </apex:column>
                 </apex:pageblockTable>

Apex command button
<apex:commandButton value="Next>>>" action="{!submitInitial}" rendered="{!initialStep}" rerender="fid"/>

Wrapper class code
 public class wrapperContact{
          public contact cnt {get; set;}
          public Boolean Oppflagvalue{get; set;}
           public  boolean submitInitial{get; set;}
          public wrapperContact (contact cnt) {
              this.cnt = cnt;
              if(cnt.Id != ApexPages.currentPage().getParameters().get('id'))
              {
                   Oppflagvalue= false;
                   if(Oppflagvalue==false)
                   {
                   submitInitial=true;
                   }
                   
               }
                        else
                        {
                                Oppflagvalue= true;
                                submitInitial=true;
                         }
                }
                    
        }

Can anyone please help me out

Thanks for the help in advance

Regards,
Jyo
Best Answer chosen by Jyosi jyosi
logontokartiklogontokartik

So basically you want to disable next if none of the checkboxes are selected, there are few ways you can achieve it, 

1. Via Javascript, 
2. or via controller method, 

Via controller, 
You can add a flag isButtonEnabled which you can set to true and re-render the commandButton, something like 

 

public boolean isButtonEnabled {get;set;}

public void checkButton() {
     
    isButtonEnabled = false; // Set to false and check wrapper list if any flag is true

    // Check the wrapper class to see if any checkboxes are checked
     for (WrapperContact wc : contactWrapperList ) {
         if (wc.Oppflagvalue) {
           isButtonEnabled = true;
           break;
         }
     }

}



 

In the visualforce page, the actionSupport will call this method and rerender the button
 

<apex:inputCheckbox value="{!cont.Oppflagvalue}" id="inputId" immediate="true" >
     <apex:actionSupport event="onclick" action="{!checkButton}"reRender="buttonId"/>
 </apex:inputCheckbox>

....
...
<apex:commandButton id="buttonId" value="Next>>>" action="{!submitInitial}" rendered="{!initialStep}" rerender="fid" disabled="{!NOT(isButtonEnabled)}"/>
 

Hope this helps.

 

All Answers

logontokartiklogontokartik
You can use the disabled attribute on inputcheckbox, something like this
 
<apex:inputCheckbox value="{!cont.Oppflagvalue}" id="inputId" immediate="true" disabled="{!NOT(cnt.Oppflagvalue)}"/>

 
Jyosi jyosiJyosi jyosi
Sorry for the confusion i need to disable to Next>>>button when checkbox is not checked
logontokartiklogontokartik

So basically you want to disable next if none of the checkboxes are selected, there are few ways you can achieve it, 

1. Via Javascript, 
2. or via controller method, 

Via controller, 
You can add a flag isButtonEnabled which you can set to true and re-render the commandButton, something like 

 

public boolean isButtonEnabled {get;set;}

public void checkButton() {
     
    isButtonEnabled = false; // Set to false and check wrapper list if any flag is true

    // Check the wrapper class to see if any checkboxes are checked
     for (WrapperContact wc : contactWrapperList ) {
         if (wc.Oppflagvalue) {
           isButtonEnabled = true;
           break;
         }
     }

}



 

In the visualforce page, the actionSupport will call this method and rerender the button
 

<apex:inputCheckbox value="{!cont.Oppflagvalue}" id="inputId" immediate="true" >
     <apex:actionSupport event="onclick" action="{!checkButton}"reRender="buttonId"/>
 </apex:inputCheckbox>

....
...
<apex:commandButton id="buttonId" value="Next>>>" action="{!submitInitial}" rendered="{!initialStep}" rerender="fid" disabled="{!NOT(isButtonEnabled)}"/>
 

Hope this helps.

 

This was selected as the best answer
Jyosi jyosiJyosi jyosi
Thanks a lot.
It worked :)

Regards,
Jyo