我尝试直接在 Javascript 中禁用 primefaces 输入组件。它是关于p:selectBooleanCheckbox
应该根据其他一些条件禁用(和启用)的(如果在另一个中填充了某个值p:inputText
)。
我的环境如下:
- JSF 莫哈拉 2.2.7
- Primefaces 5.1
- PF 扩展 3.0.0
- Apache Tomcat 7.0.47
我已经尝试了很多这样做 - 正常工作的同样事情p:inputText
不适用于p:selectBooleanCheckbox
.
JSF-部分:
<p:selectBooleanCheckbox id="thing"
widgetVar="thingWv"
disabled="#{myBB.chkboxDisabled}"
pt:pfId="thingChkBox"
styleClass="thingy"
itemLabel="The Thing"
value="#{myBB.chkbox}" />
用于禁用的 Javascript 部分:
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();
我也尝试了一些不记得的js东西......但现在我不知道如何继续。(在此之后它看起来像禁用但仍然可以检查和取消选中)
另一种方法是在 disabled 属性中添加类似#{myBB.othervalue > 5}
. 但我不喜欢这样,因为这个简单的动作需要另一个往返。