1

My p:selectCheckboxMenu automatically changes the box style when itemDisabled is true as you can see below. However, I would like the itemLabel style changes as well for disabled items. How to do that?

enter image description here

<p:selectCheckboxMenu
    id="horario"
    value="#{clienteMB.horariosSelecionados}"
    label="Selecione"
    filter="true"
    filterMatchMode="startsWith"
    required="true"
    requiredMessage="Horário: campo obrigatório."
    converter="MultiSelectEntityConverter"
    style="width:100% !important">
    <f:selectItems
        itemDisabled="#{not empty consulta.datamarc}"
        value="#{clienteMB.horarioList}"
        var="consulta"
        itemLabel="#{consulta.dataHoraFormatted()}"
        itemValue="#{consulta}">
    </f:selectItems>
</p:selectCheckboxMenu>

PS.: with p:selectManyMenu, I don't have this problem.

Marcel
  • 2,810
  • 2
  • 26
  • 46

2 Answers2

1

I could solve my problem using jQuery.

function changeDisabledItemColor() {
    jQuery("div.ui-chkbox-box.ui-widget.ui-corner-all.ui-state-default.ui-state-disabled").parent().parent().find('label').each(function(index) {
        jQuery(this).css('opacity','0.35');
    });
}

Once I have included changeDisabledItemColor() function, I just needed to add onShow="changeDisabledItemColor()" to p:selectCheckboxMenu.

This is the result:

enter image description here

halfer
  • 19,824
  • 17
  • 99
  • 186
Marcel
  • 2,810
  • 2
  • 26
  • 46
0

The HTML output generated by The above code is below

<li class="ui-selectcheckboxmenu-item ui-selectcheckboxmenu-list-item ui-corner-all ui-selectcheckboxmenu-unchecked">
<div class="ui-chkbox ui-widget">
<div class="ui-helper-hidden-accessible"><input role="checkbox" readonly="readonly" aria-checked="false" type="checkbox"></div>
<div class="ui-chkbox-box ui-widget ui-corner-all ui-state-default ui-state-disabled">
<span class="ui-chkbox-icon ui-icon ui-icon-blank"></span>
</div>
</div>
<label>A</label>
</li>

<li class="ui-selectcheckboxmenu-item ui-selectcheckboxmenu-list-item ui-corner-all ui-selectcheckboxmenu-unchecked">
<div class="ui-chkbox ui-widget">
<div class="ui-helper-hidden-accessible"><input role="checkbox" readonly="readonly" aria-checked="false" type="checkbox"></div>
<div class="ui-chkbox-box ui-widget ui-corner-all ui-state-default">
<span class="ui-chkbox-icon ui-icon ui-icon-blank"></span>
</div>
</div>
<label>C</label>
</li>

The difference between two element is ui-state-disabled class only.

Now we need one simple java script which go throw all <li> element and look for that CSS class if found we come on outer HTML and then we can assign to our custome CSS class to <label>.

Our Java Script code should run after page load. This is just and idea, it will work, we need some time to implement and some level of java script.

If you have any suggestion please write down.

I am trying to write java script for that once it done will post here.

Edited:

<script type="text/javascript">

var lis = document.getElementById("myDiv").getElementsByTagName("li");
  for(var i=0; i<lis.length;i++){
    var innerdiv = lis[i];
    var aa = lis[i].getElementsByClassName("ui-state-disabled");
    if(aa.length == 1){

lis[i].classList.add('test');

}
}
</script>

I am not java script developer you may reduce the code. but this code should run after page load.

thanks Ankush

ankush yadav
  • 422
  • 3
  • 13