[英]Add javascript change trigger to Primefaces selectonemenu
I have a quite complex form built with PrimeFaces 4.0 and i want to add some client-side jQuery/Javascript-Code which should be triggered if the value of any of the form input fields changes. 我有一个使用PrimeFaces 4.0构建的非常复杂的表单,我想添加一些客户端jQuery / Javascript-Code,如果任何表单输入字段的值发生更改,都应触发该表单。
For <p:inputText>
and <p:selectBooleanCheckbox>
I can register an event handler with $(this).change(handler);
对于
<p:inputText>
和<p:selectBooleanCheckbox>
我可以向$(this).change(handler);
注册事件处理$(this).change(handler);
How can I register this handler for a <p:selectonemenu>
? 如何为
<p:selectonemenu>
注册此处理程序? Registering the handler on the Element itself or the embedded _input
-Field doesn't trigger the handler when I change the value. 当我更改值时,在Element本身或嵌入式
_input
上注册处理程序不会触发该处理程序。
Note: I do not want to set the handler directly on the Primefaces-Tag, but dynamically via jQuery. 注意:我不想直接在Primefaces-Tag上设置处理程序,而是通过jQuery动态设置。
Any help is greatly appreciated, thanks! 非常感谢任何帮助,谢谢!
Found a solution: Primefaces creates a seperate panel for displaying the options which gets displayed if the user clicks on the <p:selectonemenu>
. 找到了解决方案:Primefaces创建了一个单独的面板来显示选项,如果用户单击
<p:selectonemenu>
这些选项就会显示出来。 The id of this panel is the id of the selectonemenu + "_panel". 该面板的ID是selectonemenu +“ _panel”的ID。 As it is a panel and not an input of any kind
click()
must be used instead of change()
Example: 由于它是一个面板,而不是任何形式的输入,因此必须使用
click()
而不是change()
示例:
$(PrimeFaces.escapeClientId($(this).attr('id')+"_panel")).click(handler);
Obviously, in the handler you have to switch back to the menu with something like this: 显然,在处理程序中,您必须使用以下命令切换回菜单:
if($(this).attr('id').endsWith('_panel')){
widget = $(PrimeFaces.escapeClientId($(this).attr('id').substring(0,$(this).attr('id').length - '_panel'.length)));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.