0

I have apex:inputCheckbox written in apex:repeat where onchange of checkbox i am calling checkedDeviations2 method which will check true or false value and push true values to array and false values will be removed from array.

Now here the issue is i am checking 2 check boxes it is working fine,when i am un checking any of the checked box first time it is returning me true,after that if i check and uncheck again it is returning false.It is very strange issue,i am unable to figure out what's wrong here.

Attaching the screenshots for reference & code.

<apex:repeat value="{!selectedDevList}" var="sd" >
    <tr>
        <td>
            <div>{!oppData.Contact__r.Name}</div>
        </td>
        <td>
            <div>{!sd.Deviation_Id__c}</div>
        </td>
        <td>
            <div>{!sd.Deviation_Description__c}
            </div>
        </td>

        <td>
            <div>{!sd.Priority__c}</div>
        </td>

        <td>
            <div>{!sd.Nature_Of_Deviation__c}</div>
        </td>
        <td>     
            <div>


                <div class="slds-form-element__row">
                    <div class="slds-form-element">
                        <label class="slds-checkbox">
                            <!--<input type='checkbox' id="{!sd.Deviation_Id__c}" class="slds-input"
onchange="checkedDeviations('{!sd.Deviation_Id__c}')"
/>-->
                            <apex:inputCheckbox id="devCheckbox2" styleclass="slds-input" 
                                                disabled="{!IF(sd.Priority__c == deviationLevel,'false','true')}"
                                                onchange="checkedDeviations2('{!sd.Deviation_Id__c}')"/>
                            <span class="slds-checkbox--faux"></span>
                        </label>
                    </div>
                </div>
            </div>

        </td>
    </tr>
</apex:repeat>

//Js part
     var selArray2 = []; 
            function checkedDeviations2(devId2){
             var checkedValue =  $('[id$=devCheckbox2]').is(':checked'); 
                alert(checkedValue);
                if(checkedValue){
                    selArray2.push(devId2);
                }
                else{
                    alert('unchecked');
                    selArray2.splice(selArray2.indexOf(devId2),1);
                }   
            }

Alert in the image shows it returns true value when unchecked

1 Answer 1

0
<apex:inputCheckbox id="devCheckbox" styleclass="slds-input" 
    disabled="{!IF(sd.Priority__c == deviationLevel,'false','true')}"
     onchange="checkedDeviations(this,'{!sd.Deviation_Id__c}')"/>  


//Js
           var selArray = []; 
            function checkedDeviations(obj,devId){
             //var checkedValue =  $('[id$=devCheckbox2]').is(':checked'); 
             alert(obj.checked);//Know whether checkbox has been checked or not.
             var checkId = $('[id$=devCheckbox]');
                if(obj.checked){
                 selArray.push(devId);  
                }
                else{
                   selArray.splice(selArray.indexOf(devId),1);
                }

            }

Got the answer. Passed 'this' in onchange attribute where this will pass the current value and get the checked and unchecked result.

The issue in my case was apex:inputCheckbox was in apex:repeat due to which same id was getting iterated and due to which if i check one checkbox it was taking value of other checkbox.

You must log in to answer this question.

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