Reputation: 175
Primefaces 5.0 selectCheckboxMenu component issue, unable to get id of checkbox in jQuery to get count of checked checkboxes.
I want to update the label text with the count of the checkboxes checked in selectCheckboxMenu
component. I have tried both the ways
Below is my code in .xhtml file. After ajax call I found an error like this.closer is undefined in primefaces.js line 22.
<p:selectCheckboxMenu id="pioDocType"
value="#{pioReportActionBean.selectedOutPutData}"
label="#{pioReportActionBean.lbl_docType}" filter="true"
filterMatchMode="startsWith" panelStyle="width:250px" styleClass="rep_checkbox" widgetVar="myCheckbox" >
<f:selectItems value="#{pioReportActionBean.inPutData}"
var="outPutData" itemLabel="#{outPutData.displayName}"
itemValue="#{outPutData.displayId}" />
<p:ajax event="change" listener="#{pioReportActionBean.populateLabelDocType}"
update="pioDocType" />
</p:selectCheckboxMenu>
jQuery code ..
var count = $("#pioDocType input:checked").length;
alert(count);
count = $("#myCheckbox:checked").length;
alert(count);
count = $("input.rep_checkbox .ui-selectcheckboxmenu-panel .ui-selectcheckboxmenu-header .ui-chkbox-box:checked").length;
alert(count);
I am using spring 3 , Primefaces 5.0 , JDk 7.
Upvotes: 2
Views: 2428
Reputation: 10048
You may try this
var count = PF('myCheckbox').inputs.filter(":checked").length;
//change label
PF('myCheckbox').jq.find('.ui-selectcheckboxmenu-label').text(count + ' selected');
Upvotes: 6