简体   繁体   English

使用JavaScript禁用p:selectBooleanCheckbox

[英]Disable p:selectBooleanCheckbox with JavaScript

How can I disable <p:selectBooleanCheckbox> component using JavaScript? 如何使用JavaScript禁用<p:selectBooleanCheckbox>组件?

My goal is to prevent user from changing value of one selectBooleanCheckbox while another is changed during ajax request time (which change values in managed bean). 我的目标是防止用户更改一个selectBooleanCheckbox的值,而在ajax请求期间更改另一个selectBooleanCheckbox的值(这会更改托管bean中的值)。

My simplified code : 我的简化代码:

<p:selectBooleanCheckbox id="..." value="..." widgetVar="abcde">
    <p:ajax listener="..." update="..."/>
</p:selectBooleanCheckbox>

<p:selectBooleanCheckbox id="..." value="...">
    <p:ajax listener="..."  update="..." onstart="alert(document.getElementById('j_idt14:locationChoice2_input').disabled);document.getElementById('j_idt14:locationChoice2_input').disabled=true;alert(document.getElementById('j_idt14:locationChoice2_input').disabled)" />
</p:selectBooleanCheckbox>

j_idt14:locationChoice2_input id is the id of my first <p:selectBooleanCheckbox /> component. j_idt14:locationChoice2_input id是我的第一个<p:selectBooleanCheckbox />组件的ID。

alert() functions dsplay false and after true so my component is well disabled. alert()函数使dsplay为false ,然后为true因此我的组件被禁用。

However, it stays with the same render event if it's disabled. 但是,如果禁用,它将保留相同的渲染事件。

Is the only way to be changing manually CSS classes to match disabled state ? 是手动更改CSS类以匹配禁用状态的唯一方法吗? Can widgetVar help me ? widgetVar可以帮助我吗?

nb: I want to change immediately the aspect of the component so I don't use the JSF disabled attribute, I have to use JS. nb:我想立即更改组件的外观,因此我不使用disabled JSF的属性,而必须使用JS。

I answer my own question. 我回答我自己的问题。

I put inside simple panelGrid my 2 selectBooleanCheckbox and apply blockUI on this panelGrid : 我将2 selectBooleanCheckbox放到了简单的panelGrid并在此panelGrid上应用blockUI

<p:blockUI block="panelToBlock" widgetVar="block" />

<h:panelGrid id="panelToBlock">
   <p:selectBooleanCheckbox id="..." value="..." widgetVar="abcde">
      <p:ajax listener="..." update="..." onstart="block.show()" oncomplete="block.hide()" />
   </p:selectBooleanCheckbox>

   <p:selectBooleanCheckbox id="..." value="...">
      <p:ajax listener="..."  update="..." onstart="block.show()" oncomplete="block.hide()" />
   </p:selectBooleanCheckbox>

</h:panelGrid>

blockUI has a default opacity value to 0.3 but I don't want to see it, I just want to disable my 2 selectBooleanCheckbox so I change the value of the generated id to 0 at runtime with JS : blockUI的默认不透明度值为0.3但我不想看到它,我只想禁用我的2 selectBooleanCheckbox所以我在运行时使用JS将生成的id的值更改为0

$(window).load(function() {

   $('#j_idt14\\:j_idt23_blocker').css('opacity', 0);

}

and that's all. 就这样。

Now when ajax request is made, these 2 checkboxes values can not be changed. 现在,当发出ajax请求时,无法更改这2个复选框的值。

Hope this helps 希望这可以帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 JavaScript 设置 p:selectBooleanCheckbox 的值 - How to set value of p:selectBooleanCheckbox with JavaScript 如何检查全部 <p:selectBooleanCheckbox/> 通过使用javaScript选中一个复选框来实现布尔复选框 - How to check all <p:selectBooleanCheckbox/> boolean Checkboxes by checking one check box with javaScript Primefaces p:selectBooleanCheckBox 不显示复选标记 - Primefaces p:selectBooleanCheckBox does not show the check mark 如何在检查p:selectBooleanCheckbox时打开确认对话框 - How to open a confirm dialog on check of p:selectBooleanCheckbox selectBooleanCheckbox中的javascript函数的参数损坏 - Damaged parameter of javascript function in selectBooleanCheckbox Javascript(JQuery)-如何为Chrome禁用Ctrl + P - Javascript (JQuery) - How to disable Ctrl + P for Chrome 如何知道是否使用JavaScript选择了primefaces selectBooleanCheckbox? - How to know that primefaces selectBooleanCheckbox is selected or not using javascript? 如何通过使用JavaScript获得JSF selectBooleanCheckbox的值? - How to get a value of JSF selectBooleanCheckbox by using JavaScript? 如何禁用 <h:selectBooleanCheckbox> 按下 <a4j:commandButton> 在jsf中 - How disable a <h:selectBooleanCheckbox> pressing a <a4j:commandButton> in jsf 如何在按下CTRL + P后使用JavaScript禁用打印弹出窗口 - How to disable print pop up with JavaScript after pressing CTRL + P
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM