Select all items in checkbox group with CSJS?

2019-09-04 01:49发布

I am able to select all of the items in a checkbox group with SSJS by simply setting the component's value.

But how would I do this in CSJS?

标签: xpages
4条回答
我欲成王,谁敢阻挡
2楼-- · 2019-09-04 02:04

You select them with dojo.query and set the selected property to true. You need to check: every box will have its own ID, but the beginning of it is the same -or- you use a class. Or you look for the first and then select all siblings.

The strategy depends on your application's needs.

Check the dojo.query documentation for your options.

查看更多
淡お忘
3楼-- · 2019-09-04 02:09

this is how you do it in jquery

$("[name$=checkBoxGroup1]").attr("checked",true)
查看更多
手持菜刀,她持情操
4楼-- · 2019-09-04 02:09

Simplifying Naveen's answer, this worked great for me:

dojo.query("input[name=\"#{id:checkBoxGroup1}\"]").forEach( function(node) {
        node.checked = true; 
    });
查看更多
在下西门庆
5楼-- · 2019-09-04 02:12

Assuming that the name of your check box group is checkBoxGroup this code snippet of check all checkbox should do the trick for you.

<xp:checkBox text="Check all" id="chkCheckAll">
    <xp:eventHandler event="onclick" submit="false">
        <xp:this.script><![CDATA[dojo.query("input[name=\"#{id:checkBoxGroup}\"]").forEach(
    function(node) {
        node.checked = document.getElementById("#{id:chkCheckAll}").checked;
    }
)]]></xp:this.script>
    </xp:eventHandler>
</xp:checkBox>
查看更多
登录 后发表回答