[英]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.