1

I got a pageblock table displays some values each records in the table has a checkbox to select. I want to disable all other checkboxes when one is selected. (My pageblocktable returns values depending on a string search and StdSet controller paginator also enabled)

My wrapper class----------

public class MarketEntityWrapper{
        public Market_Entity__c tMarketEntity {get; set;}
        public boolean checked {get; set;}

        public MarketEntityWrapper(){
            tMarketEntity = new Market_Entity__c();
            checked = false;
        }

        public MarketEntityWrapper(Market_Entity__c m){
            tMarketEntity = m;
            checked = false;
        }
    }

VF pageblocktable--------------

<apex:outputPanel layout="block" style="overflow:auto;height:250px" >
    <apex:pageBlockTable value="{!marketEntitySearchWrappers}" var="markEnt">
    <apex:column>
        <apex:inputCheckbox value="{!markEnt.checked}" disabled="{!IF(Account.check__c==true,true,false)}"/>
    <!--can I use actionsupport here??-->
    </apex:column> 
    <apex:column headerValue="{!$Label.Marketentity_string_search_Name}" value="{!markEnt.tMarketEntity.Name}"/>
   <apex:column headerValue="{!$Label.Marketentity_string_search_Postcode}" value="{!markEnt.tMarketEntity.Postcode__c}"/>
   <apex:column headerValue="{!$Label.Marketentity_string_search_SPID}" value="{!markEnt.tMarketEntity.SPID__c}"/>
   <apex:column headerValue="{!$Label.Marketentity_string_search_OrgId}" value="{!markEnt.tMarketEntity.OrgId__c}"/>
    </apex:pageBlockTable>      
  </apex:OutputPanel>

1 Answer 1

2

Create a variable in apex class

public Id  idSelected {get; set;} // this will contain the selected record id

create a method

public void disableCheckbox()
{
//iterate over your wrapper and set markEnt.checked false except selected one
   for(MarketEntityWrapper obj: marketEntitySearchWrappers)
   {
        if(obj.tMarketEntity.Id == idSelected && markEnt.checked){

        }
        else{
          markEnt.checked = false;
        }
   }
}

in VF page on click on checked call a action function and pass record id

<apex:actionFunction name="AF" action="{!disableCheckbox}"  rerender="actionFunc1">
        <apex:param name="selectItemId" value="" assignedTo="{!idSelected}"/>       
    </apex:actionFunction>


    <apex:outputPanel layout="block" style="overflow:auto;height:250px" id="actionFunc1">
    <apex:pageBlockTable value="{!marketEntitySearchWrappers}" var="markEnt">
    <apex:column>
        <apex:inputCheckbox onclick="AF('{!markEnt.tMarketEntity.Id}')" value="{!markEnt.checked}" disabled="{!IF(markEnt.checked==true,true,false)}"/>
    </apex:column> 
    <apex:column headerValue="{!$Label.Marketentity_string_search_Name}" value="{!markEnt.tMarketEntity.Name}"/>
   <apex:column headerValue="{!$Label.Marketentity_string_search_Postcode}" value="{!markEnt.tMarketEntity.Postcode__c}"/>
   <apex:column headerValue="{!$Label.Marketentity_string_search_SPID}" value="{!markEnt.tMarketEntity.SPID__c}"/>
   <apex:column headerValue="{!$Label.Marketentity_string_search_OrgId}" value="{!markEnt.tMarketEntity.OrgId__c}"/>
    </apex:pageBlockTable>      
  </apex:OutputPanel>
3
  • im getting an error on action="{!toggleMMcheckbox}" because there's no method to refer for that ?
    – Tinkerbell
    Commented Nov 19, 2015 at 17:23
  • it should be disableCheckbox() method right ?
    – Tinkerbell
    Commented Nov 19, 2015 at 17:25
  • 1
    don't blindly copy the code.. I just provided an example . yes it is disableCheckbox
    – Ratan Paul
    Commented Nov 19, 2015 at 17:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .