disableing primefaces selectBooleanCheckbox using javascript

580 Views Asked by At

I try to disable a primefaces input component directly in Javascript. It is about a p:selectBooleanCheckbox that should be disabled (and enabled) based on some other conditions (if certain value is filled in another p:inputText).

My environment looks like:

  • JSF Mojarra 2.2.7
  • Primefaces 5.1
  • PF Extensions 3.0.0
  • Apache Tomcat 7.0.47

I've tried already a lot to do so - same things working for normal p:inputText are not working for the p:selectBooleanCheckbox.

JSF-Part:

   <p:selectBooleanCheckbox id="thing"
      widgetVar="thingWv"
      disabled="#{myBB.chkboxDisabled}"
      pt:pfId="thingChkBox"
      styleClass="thingy"
      itemLabel="The Thing"
      value="#{myBB.chkbox}" />

Javascript part for disabling:

   console.log ('disable the thing' );
   $('[pfId*=thingChkBoxLabel]').addClass("ui-state-disabled");
   $('[pfId*=thingChkBox]').addClass("ui-state-disabled");
   $('[pfId*=thingChkBox]').prop('disabled', true);
   $('[pfId*=thingChkBox]').attr('disabled', 'disabled');
   $('[pfId*=thingChkBox] > div > input').addClass("ui-state-disabled");
   $('[pfId*=thingChkBox] > div > input').prop('disabled', true);
   $('[pfId*=thingChkBox] > div > input').attr('disabled', 'disabled');
   $('[pfId*=thingChkBox] > div.ui-chkbox-box').addClass("ui-state-disabled");
   $('[pfId*=thingChkBox] > div.ui-chkbox-box').prop('disabled', true);
   $('[pfId*=thingChkBox] > div.ui-chkbox-box').attr('disabled', 'disabled');
   PF('thingWv').disable();

I've also tried some more js things didn't remember ... but now I don't know how to proceed. (after this it looks like disabled but checking and unchecking is still possible)

Another way would be a and having in the disabled attribute something like #{myBB.othervalue > 5}. But I don't like this as it needs another round trip for this simple action.

0

There are 0 best solutions below