1
votes

I am trying to find how to make an onChange event for a check box initiate a button press for a button on the same page. I have had a search on google but can't find how this is done. Is such a thing possible in xpages?

EDIT: More information and code

My problem is the users run a search and want the option to omit cancelled records or include them. I tried for days to get the view to update just by clicking on a checkbox but it would only refresh after the user changed the check box value and clicked somewhere on the page. I tried partial refresh and complete refresh etc on the check box to refresh the dynamicviewpanel etc. I tried using viewScope variables to determine the check box value but nothing worked. I found it worked if I included a button to do a complete refresh and I thought I could hide the button and have the check box click the button. I have tried adding Knut's suggestion below but it still only works when I click also the button or somewhere else on the page.

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core"
   xmlns:xe="http://www.ibm.com/xsp/coreex"
   xmlns:xc="http://www.ibm.com/xsp/custom">

   <xp:eventHandler event="onClientLoad" submit="false">
     <xp:this.script><![CDATA[dojo.query(".xspLinkViewColumn").attr
        ("target", "_blank");]]></xp:this.script>
   </xp:eventHandler>
   <xc:OneUILayout id="cc4cconeuilayout"
     navigationPath="/OneUI/SearchPage">
   <xp:this.facets>
      <xp:panel xp:key="LeftColumn" id="panel4">
         <xc:LeftOneUI id="cc4ccLeftOneUI"></xc:LeftOneUI>
      </xp:panel>
   </xp:this.facets>
   <xp:panel>
     <xp:label value="This is the result of the search page"
       id="label5" style="font-weight:bold">
     </xp:label>
     <xp:br></xp:br>
     <xp:br></xp:br>

     <xp:label value="Search String:" id="label1"></xp:label>
     <xp:inputText id="inputText1" value="#
       {param.search}"></xp:inputText>

     <xp:checkBox text="Cancelled Contracts Omitted" id="OmitCancelled" 
        value="#{viewScope.test}" style="padding-left:3.0em">
       <xp:eventHandler event="onchange" submit="false">
         <xp:this.script><![CDATA[document.getElementById('#
           {id:button1}').click()]]></xp:this.script>
       </xp:eventHandler>
     </xp:checkBox>
     <xp:button value="Refresh Omitting"
        id="button1" style="margin-left:2.0em">
        <xp:eventHandler event="onclick"
           submit="true" refreshMode="complete">
           <xp:this.script><![CDATA[alert("hi")]]></xp:this.script>
        </xp:eventHandler>
     </xp:button>

    <xp:panel id="maincontentpanel">
       <xe:dynamicViewPanel rows="50" id="dynamicViewPanel1"
           width="100%" partialRefresh="true">
        <xe:this.data>
        <xp:dominoView var="view">
           <xp:this.viewName>
    <![CDATA[#{javascript:if(getComponent
                 ('OmitCancelled').isChecked()){
                      viewName = "ContractsFlatByYear"
                     }else {
                       viewName = "ContractsFlatByYearandCancelled"
                  }}]]>
           </xp:this.viewName>
          <xp:this.search><![CDATA[#{javascript:return param.search;}]]>
           </xp:this.search>
     </xp:dominoView>
    </xe:this.data>

   </xe:dynamicViewPanel>
  </xp:panel>
 </xp:panel>
</xc:OneUILayout>
</xp:view>
1

1 Answers

3
votes

This is an example for automatically clicking a button on checkbox' onchange event:

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
    <xp:checkBox
        text="check it"
        id="checkBox1"
        value="#{viewScope.test}">
        <xp:eventHandler
            event="onchange"
            submit="false">
            <xp:this.script><![CDATA[
                document.getElementById('#{id:button1}').click()
            ]]></xp:this.script>
        </xp:eventHandler>
    </xp:checkBox>
    <br />
    <xp:button
        value="Label"
        id="button1">
    <xp:eventHandler
        event="onclick"
        submit="false">
        <xp:this.script><![CDATA[alert("hi")]]></xp:this.script>
    </xp:eventHandler></xp:button>
</xp:view>