Toggle <p:selectcheckboxmenu> items in JavaScript

时间:2015-09-14 15:53:23

标签: javascript jsf primefaces

How can I select or unselect items in <p:selectCheckboxMenu> component using JavaScript?

I have figured out only this way:

PF('selectCheckboxMenuWidgetVar').checkboxes[index_of_item].click();

But this generates "click" on element and invokes all handlers. I want only (un)select item without invoking handlers.

1 个答案:

答案 0 :(得分:1)

I found an answer:

var widgetVar = PF('selectCheckboxMenuWidgetVar');

check:

widgetVar.check($(widgetVar.checkboxes[index_of_item]));
$(widgetVar.inputs[index_of_item]).prop('checked', true);

uncheck:

widgetVar.uncheck($(widgetVar.checkboxes[index_of_item]));
$(widgetVar.inputs[index_of_item]).prop('checked', false);

it is working for me.