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
ckellieckellie 

Checkedone is not working with a wrapper class

I have a list of checkboxes in a wrapper class/pageblocktable that I want to limit the user to only choose one box.

Below is my script
function checkone(cb,conid)
{

   var inputElem = document.getElementsByTagName("input");
    for(var i=1; i<inputElem.length; i++)
    {
        if(inputElem[i].id.indexOf("checkedone")!=-1)
        {
            if(inputElem[i].name!=cb.name)
            {
                inputElem[i].checked=false;
            }
        }
    }
  
  
}

This automation is working great if I assign the checkbox to the records id and not the selected element:
<input type="checkbox" name="{!cp.con.id}" id="checkedone"  onclick="return checkone(this,'{!cp.con.id}')"  />

but when I use the selected element of the wrapper class the automation does not work.
<input type="checkbox" name="{!cp.selected}" id="checkedone"  onclick="return checkone(this,'{!cp.selected}')"  />

How do I change my function to control cp.selected, or change my wrapper class to process cp.con.id when the checkbox is selected? Below is my visualforce page and apex class

VFpage:
<apex:page standardcontroller="App_Matrix__c" extensions="ApplicationDefiner" tabStyle="App_Matrix__c" sidebar="false" showChat="false">
<script>
function checkone(cb,conid)
{

   var inputElem = document.getElementsByTagName("input");
    for(var i=1; i<inputElem.length; i++)
    {
        if(inputElem[i].id.indexOf("checkedone")!=-1)
        {
            if(inputElem[i].name!=cb.name)
            {
                inputElem[i].checked=false;
            }
        }
    }
  
  
}
</script>  

    <apex:sectionHeader title="Application Solution"/>
<apex:form >

    <apex:pageBlock title="Select Primary Application" mode="view"> 
           <apex:pageBlockButtons >
                <apex:commandButton value="Process Selected" action="{!processSelected}" rerender="resultTemtbl" />
            </apex:pageBlockButtons>
       <apex:pageblockTable value="{!CProduct}" title="Select Primary Application" var="cp" id="pbselecttbl">

       <apex:column headerValue="Primary Application" width="50px">

       <input type="checkbox" name="{!cp.selected}" id="checkedone"  onclick="return checkone(this,'{!cp.selected}')"  />
       <!--    <input type="checkbox" name="{!cp.con.id}" id="checkedone"  onclick="return checkone(this,'{!cp.con.id}')"  />  -->
        </apex:column>
           <apex:column value="{!cp.con.name}" headerValue="Name" width="60px"/>
           <apex:column value="{!cp.con.Condition_1__c}" headerValue="Primary Condition" width="60px"/>
           <apex:column value="{!cp.con.Condition_2__c}" headerValue="Additional Condition" width="60px"/>
           <apex:column value="{!cp.con.Shape_1__c}" headerValue="Primary Shape" width="60px"/>
           <apex:column value="{!cp.con.Shape_2__c}" headerValue="Additional Shape" width="60px"/>
           <apex:column value="{!cp.con.Defect_Description__c}" headerValue="Sort Criteria"/>
       
       </apex:pageblockTable><br/><br/>
    </apex:pageBlock><br/><br/> 
    <apex:pageBlock title="Template ID" mode="view" >  
       <apex:pageblockTable value="{!Configuration}" Title="Template ID" var="cp" id="resultTemtbl">

           <apex:column value="{!cp.name}" headerValue="Template ID" width="30px"/>
           <apex:column value="{!cp.Base_Model__c}" headerValue="Base Model" width="30px"/>
           <apex:column value="{!cp.Customer_Product__r.name}" headerValue="Name" width="40px"/>
           <apex:column value="{!cp.Condition_1__c}" headerValue="Primary Condition" width="60px"/>
           <apex:column value="{!cp.Condition_2__c}" headerValue="Additional Condition" width="60px"/>
           <apex:column value="{!cp.Shape_1__c}" headerValue="Primary Shape" width="60px"/>
           <apex:column value="{!cp.Shape_2__c}" headerValue="Additional Shape" width="60px"/>
           <apex:column value="{!cp.Defect_Description__c}" headerValue="Sort Criteria"/>
       
       </apex:pageblockTable>

    </apex:pageBlock>

</apex:form>
</apex:page>
Apex Class:
public with sharing class ApplicationDefiner {

    public ApplicationDefiner(ApexPages.StandardController controller) {
  oid =[SELECT id from Opportunity WHERE id =:ApexPages.currentPage().getParameters().get('oppid')].id;

    }

    id oid;
    public List<cCustomer> cpList {get; set;}
    public List<App_Matrix__c> aplist {get; set;}
    Boolean cpprimary;
    List<Customer_Product_Line_Item__c> selectedCpli = new List<Customer_Product_Line_Item__c>();
    Public Map<string, App_Matrix__c> apmap = new Map<string, App_Matrix__c>();
    Set<String> cpset = new Set<String>();
    Set<String> cpprimaryset = new Set<String>();


    public List<cCustomer> getCProduct() {
            cplist = new List<cCustomer>();
            for(Customer_Product_Line_Item__c c: [select id, Combo__c, Name, Customer_Product__r.Name,Condition_1__c, 
                    Condition_2__c,Shape_1__c, Shape_2__c,Defect_Description__c, Opportunity__c from Customer_Product_Line_Item__c where Opportunity__c =: oid]) {

                cplist.add(new cCustomer(c)); 
       }
        return cplist;
    }    


    public PageReference processSelected() {

        for(cCustomer cCon: cplist) {
            if(cCon.selected == true) {
                selectedCpli.add(cCon.con);

            }
               System.debug('#####'+cCon.selected);
        }

        System.debug('These are the selected Contacts...');
        for(Customer_Product_Line_Item__c con: selectedCpli) {
            cpset.add(con.combo__c);
            system.debug(con);
        }
         system.debug(cpset);
        cplist=null;
        return null;
    }

    public List<App_Matrix__c> getConfiguration() {
            aplist = new List<App_Matrix__c>();
            for(App_Matrix__c ac: [select Name, Base_Model__c, Customer_Product__r.name, Condition_1__c, Condition_2__c,Shape_1__c, Shape_2__c,combo__c,Defect_Description__c from App_Matrix__c where combo__c in: cpset]) {

                aplist.add(ac);
                System.debug('%%%%%%%%%%id'+ac.id);

            }
        return aplist;
    }



    public class cCustomer {
        public Customer_Product_Line_Item__c con {get; set;}
        public Boolean selected {get; set;}

        public cCustomer (Customer_Product_Line_Item__c c) {
            con = c;
            selected = false;
        }
    }
    
}

Thank you for your help



 
Amit Chaudhary 8Amit Chaudhary 8
Please check below post. I hope that will help u 
http://salesforce.stackexchange.com/questions/11671/adding-radio-button-in-wrapper-class
http://salesforce.stackexchange.com/questions/32909/pagereference-does-not-direct-to-selected-radio-button
http://www.sfdcpoint.com/salesforce/wrapper-class-in-apex/

Please modify below code and set all other check box as false when user will select any new check box.

<script type="text/javascript">
        function selectAllCheckboxes(obj,receivedInputID)
       {
            var inputCheckBox = document.getElementsByTagName("input");
            for(var i=0; i<inputCheckBox.length; i++)
               {
                if(inputCheckBox[i].id.indexOf(receivedInputID)!=-1){
                    inputCheckBox[i].checked = obj.checked;
                }
            }
        }
    </script>
 <apex:inputCheckbox onclick="selectAllCheckboxes(this,'inputId')"/>

Please let us know if this will help u

Thanks
Amit Chaudhary
 
ckellieckellie
Thank you Amit for the post. Unfortunately the links and the javascript does not correct the problem.  When I make the changes, the I can select more than one record in the list.