I am trying to validate a checkbox is checked on click of a apex commandlink. I am using SLDS styling on the page and the problem seems to be with the SLDS checkbox. I am using the below code as specified in https://www.lightningdesignsystem.com/components/checkbox/ When I check the idChkbox, the onClick function always prints 'idChkbox Unchecked' alert. After digging a bit more on SLDS checkbox, found this SLDS-checkbox thread. I am still not able to get the proper state of checkbox.
My Checkbox Code:
<div class="slds-form-element">
<div class="slds-form-element__control">
<span class="slds-checkbox">
<input type="checkbox" name="options" id="idChkbox" value="{!confirm}" rendered="{!renderConfirm}" />
<label class="slds-checkbox__label" for="idChkbox">
<span class="slds-checkbox_faux"></span>
<span class="slds-form-element__label">my label here</span>
</label>
</span>
</div>
</div>
Commandlink code:
<apex:commandLink id="selectLink" onclick="return jsFunction('{!record.id}')" action="{!save}" styleClass="cmdLink"> Select
<apex:param name="streetAddr" value="{!record.strretAddr}" />
<apex:param name="cityName" value="{!record.cityName}" />
<apex:param name="zipCode" value="{!record.zipCode}" />
jsFunction:
function jsFunction(element){
if(element != null){
var valConfirm = j$('[id$=idChkbox]').prop('checked');
if(!j$('[id$=idChkbox]').is(':checked')){
alert (' idChkbox Unchecked ' );
valConfirm = false;
document.getElementById('error_wrapper').style.display = 'block';
}
else{
alert (' Confirm Checked ' + valConfirm);
setConfirm(valConfirm); // my actionFunction which sends the value of confirm to controller
}
}
}
myJSFunctionscript as well as the VF tag for the checkbox? Both are pretty critical to the discussion. – Mark Pond Mar 29 '18 at 21:47