jquery - Select all items in Multiple SelectManyCheckBox with dynamic ids -


i want select check box in groups of checkboxes using primefaces component on top of jsf.

my code this:

<h:panelgrid columns="2" style="margin-bottom:10px" cellpadding="5">     <p:outputlabel value="confere:" style="font-weight:bold!important" />     <p:selectmanycheckbox         value="#{funcionariobean.funcionario.permissaoconfere.stringarray}">         <f:selectitem itemlabel="consulta" itemvalue="c" />         <f:selectitem itemlabel="edição" itemvalue="e" />         <f:selectitem itemlabel="deleção" itemvalue="d" />         <f:selectitem itemlabel="inclusão" itemvalue="i" />         <f:selectitem itemlabel="relatório" itemvalue="r" />         <f:selectitem itemlabel="check all"/>     </p:selectmanycheckbox> </h:panelgrid> <h:panelgrid columns="2" style="margin-bottom:10px" cellpadding="5">     <p:outputlabel value="visitante:" style="font-weight:bold!important" />     <p:selectmanycheckbox         value="#{funcionariobean.funcionario.permissaovisitante.stringarray}">         <f:selectitem itemlabel="consulta" itemvalue="c" />         <f:selectitem itemlabel="edição" itemvalue="e" />         <f:selectitem itemlabel="deleção" itemvalue="d" />         <f:selectitem itemlabel="inclusão" itemvalue="i" />         <f:selectitem itemlabel="relatório" itemvalue="r" />         <f:selectitem itemlabel="check all"/>     </p:selectmanycheckbox> </h:panelgrid> <h:panelgrid columns="2" style="margin-bottom:10px" cellpadding="5">     <p:outputlabel value="ocorrências:" style="font-weight:bold!important" />     <p:selectmanycheckbox         value="#{funcionariobean.funcionario.permissaoocorrencia.stringarray}">         <f:selectitem itemlabel="consulta" itemvalue="c" />         <f:selectitem itemlabel="edição" itemvalue="e" />         <f:selectitem itemlabel="deleção" itemvalue="d" />         <f:selectitem itemlabel="inclusão" itemvalue="i" />         <f:selectitem itemlabel="relatório" itemvalue="r" />         <f:selectitem itemlabel="check all"/>     </p:selectmanycheckbox> </h:panelgrid> 

i tried code posted here works, if have 1 group of checkboxes on page.

wrap in reusable composite component below:

/resources/composites/selectmanycheckboxall.xhtml

<ui:component     xmlns="http://www.w3.org/1999/xhtml"     xmlns:f="http://xmlns.jcp.org/jsf/core"     xmlns:h="http://xmlns.jcp.org/jsf/html"     xmlns:ui="http://xmlns.jcp.org/jsf/facelets"     xmlns:cc="http://xmlns.jcp.org/jsf/composite"     xmlns:p="http://primefaces.org/ui" >     <cc:interface>         <cc:attribute name="value" />         <cc:editablevalueholder name="input" targets="checkboxes" />     </cc:interface>     <cc:implementation>         <h:outputstylesheet library="composites" name="selectmanycheckboxall.css" target="head" />         <h:outputscript library="composites" name="selectmanycheckboxall.js" target="head" />         <div id="#{cc.clientid}" class="checkboxes-all"              data-widget-checkboxes="#{p:widgetvarfromcontext('checkboxes', cc).split('\'')[1]}"              data-widget-all="#{p:widgetvarfromcontext('all', cc).split('\'')[1]}">             <p:selectmanycheckbox id="checkboxes" value="#{cc.attrs.value}">                 <cc:insertchildren />             </p:selectmanycheckbox>             <div class="all">                 <p:selectbooleancheckbox id="all" />                 <p:outputlabel for="all" value="check all" />             </div>         </div>     </cc:implementation>           </ui:component> 

/resources/composites/selectmanycheckboxall.css

.checkboxes-all {     white-space:  nowrap; }  .checkboxes-all .ui-selectmanycheckbox, .checkboxes-all .all {     display: inline-block;     vertical-align: middle; }  .checkboxes-all .all .ui-chkbox {     margin: 1px 4px 0 0;     vertical-align: top; }  .checkboxes-all .all label {     display: inline-block;     margin-top: 4px; } 

/resources/composites/selectmanycheckboxall.js

$(document).on("click", ".checkboxes-all .all .ui-chkbox-box, .checkboxes-all .all input", function() {     var $composite = $(this).closest(".checkboxes-all");     var widgetall = primefaces.widgets[$composite.data("widget-all")];     var widgetcheckboxes = primefaces.widgets[$composite.data("widget-checkboxes")];      widgetcheckboxes.inputs.prop("checked", !widgetall.ischecked()).click(); });  $(document).on("click", ".checkboxes-all .ui-selectmanycheckbox input", function() {     var $composite = $(this).closest(".checkboxes-all");     var widgetall = primefaces.widgets[$composite.data("widget-all")];      if (!$(this).is(":checked") && widgetall.ischecked()) {         widgetall.uncheck();     } }); 

usage:

<html xmlns:my="http://xmlns.jcp.org/jsf/composite/composites"> ... <my:selectmanycheckboxall value="#{bean.selecteditems}">     <f:selectitem itemlabel="consulta" itemvalue="c" />     <f:selectitem itemlabel="edição" itemvalue="e" />     <f:selectitem itemlabel="deleção" itemvalue="d" />     <f:selectitem itemlabel="inclusão" itemvalue="i" />     <f:selectitem itemlabel="relatório" itemvalue="r" /> </my:selectmanycheckboxall> 

Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -