This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal



Jul 4, 2013, 4:22 PM
110 Posts
topic has been resolvedResolved

Show an initially hidden panel when checkbox is checked

  • Category: Dojo and Client Side JavaScript
  • Platform: Windows
  • Release: 9.0
  • Role: Developer
  • Tags: checkbox,panel
  • Replies: 3

I have a panel which by default visible is false. Then I have a checkbox which by default is unchecked. How do I show the panel when the checkbox is checked and hide again when it's unchecked? I've tried below code but I always getting the error 'dojo.byId("mypanel")" is null. But if the panel is by default shown, then I won't be getting this error.

This code is on the client side of the checkbox onChange event:

if (document.getElementById("#{id:mycheckbox}").checked) {
       document.getElementById("#{id:mypanell}").style.display = 'block';
} else {
      document.getElementById("#{id:mypanel}").style.display = 'none';
}

I've also tried removing the onChange CSJS code and replace it with an onChange SSJS with partial refresh to the panel and the panel visibility is computed as:

getComponent("mycheckbox").isChecked()

but it always return the error "No element to submit with ... mypanel".

Jul 4, 2013, 6:38 PM
54 Posts
hide when

Look at this sample:

 

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" xmlns:xc="http://www.ibm.com/xsp/custom">
    <xp:eventHandler event="onClientLoad" submit="true"
        refreshMode="norefresh">
    </xp:eventHandler>   
    <xp:br></xp:br>
    <xp:checkBoxGroup id="checkBoxGroup1" defaultValue="0">
        <xp:selectItem itemLabel="checked" itemValue="0"></xp:selectItem>
        <xp:selectItem itemLabel="unchecked" itemValue="1"></xp:selectItem>
        <xp:eventHandler event="onchange" submit="true"
            refreshMode="partial" refreshId="panel1">
        </xp:eventHandler>
    </xp:checkBoxGroup>
    <xp:br></xp:br>
    <xp:br></xp:br>
    <xp:panel id="panel1">
        <xp:panel>
            content of&#160;panel
            <xp:this.rendered><![CDATA[#{javascript:getComponent('checkBoxGroup1').value == "1"}]]></xp:this.rendered><xp:span rendered="false"></xp:span>
        </xp:panel>
    </xp:panel>
    <xp:br></xp:br>
</xp:view>


 

Jul 6, 2013, 3:42 PM
1 Posts
element have to be rendered

Your 'mypanell' have to be visible (rendered="true", which is the default), but hidden with css (style="display: none;"initially.

Then you can use your code for a client side toggle of visibility.

 

Also check the right spelling of the IDs you use ( mypanellmypanel).

Jul 7, 2013, 6:32 PM
110 Posts
Thanks for simple solution

Thanks Alexander and Helmut! Wonder why didn't I thought of using display:none when I'm already using it in my CSJS code. Also when I search the web for 'XPages show component when checkbox is checked', all the answers are usually complicated ones involving getvalue() and partial refresh etc. I've read somewhere before that using styling/CSS to show/hide your component isn't really hiding in terms of security which would allow hacker access.

Also, in terms of mimicking real paper form, a checked checkbox will meant 'Yes' and if it's not checked it'll mean 'No' which explains why I'm not using any checkbox group or radio button group controls.

Anyway it works now. Thanks again.


This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal