FORUM PLAN UPDATE
Date revision: This forum will remain open to new posts and responses until December 1, 2018. (After that date, you will still be able to view and search the forum.) Also, we're taking a second look at the best place to host future conversation. For now, keep using this forum, and stay tuned for more news.



Jun 11, 2012, 10:16 AM
68 Posts

Re: Disabling groups of checkboxes not all. Getting values from documents.

  • Category: Dojo and Client Side JavaScript
  • Platform: All
  • Release: 8.5.3
  • Role: Administrator
  • Tags:
  • Replies: 4
Great to hear you Simon.
 
As always you are very helpful. I found a little bug in your code (or maybe I made it buggy):
 
 var list = repeat.getElementsByTagName('input');
 
instead of:
 
var list = repeat.elementsByTagName('input'); 
 
But still it don't work at all... The code is pretty simple I tried to make disable all checkbox in repeat after check (for test your function). But as a interior script (in repeat control) this don't work at all.
 
This is script:
 
var repeat = dojo.byId('#{id:repeat1}');
var list = repeat.getElementsByTagName('input');  <== Here is problem I "debuged" it and write alert("debug") after this don't work so here is some error probably.

for(x in list)
{
   if(list[x].type == "checkbox")
   {
       list[x].disabled = true;
   }
 
But there is a strange thing I made button above repeat control, and it partial work - it simply disable all checkboxes on page :)
 
 
Here is code of all (same only for test so its not so big):
 
 <xp:button value="Button Above Repeat" id="button3">
        <xp:eventHandler event="onclick" submit="false">
            <xp:this.script><![CDATA[var repeat = dojo.byId('#{id:repeat1}');
var list = repeat.getElementsByTagName('input');

for(x in list)
{
   if(list[x].type == "checkbox")
   {
       list[x].disabled = true;
   }
} ]]></xp:this.script>
        </xp:eventHandler></xp:button>
    <xp:br></xp:br><xp:repeat id="repeat1" rows="30" first="0" indexVar="index">

        <xp:this.value><![CDATA[#{javascript:return [0,1,2];}]]></xp:this.value>

        <xp:br></xp:br>

        <xp:text escape="true" id="computedField1">
            <xp:this.value><![CDATA[#{javascript:return "Repeat no: "+index;}]]></xp:this.value>
        </xp:text>
        <xp:br></xp:br><xp:button id="button4">
        <xp:this.value><![CDATA[#{javascript:return "Button Inside Repeat no: "+index;}]]></xp:this.value>
        <xp:eventHandler event="onclick" submit="false">
            <xp:this.script><![CDATA[var repeat = dojo.byId('#{id:repeat1}');
var list = repeat.getElementsByTagName('input');

for(x in list)
{
   if(list[x].type == "checkbox")
   {
       list[x].disabled = true;
   }
} ]]></xp:this.script>
        </xp:eventHandler></xp:button>
        <xp:repeat id="repeat2" rows="30" indexVar="index2">
            <xp:this.value><![CDATA[#{javascript:return [0,1,2,3,4,5,6];}]]></xp:this.value>
            <xp:checkBox text="#{javascript:return index2;}" id="checkBox1">


                <xp:eventHandler event="onchange" submit="false">
                    <xp:this.script><![CDATA[var repeat = dojo.byId('#{id:repeat1}');
var list = repeat.getElementsByTagName('input');

for(x in list)
{
   if(list[x].type == "checkbox")
   {
       list[x].disabled = true;
   }
} ]]></xp:this.script>
                </xp:eventHandler>

            </xp:checkBox>
            <xp:br></xp:br>
        </xp:repeat>
    </xp:repeat>
 
UPDATE:
 
I have changed in inside inside buttons repeat1 to repeat2 and this works but problem is when I want to make this as a  onChange event in checkboxes - it don't work why ? Full code:
 
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:button value="Button Above Repeat" id="button3">
        <xp:eventHandler event="onclick" submit="false">
            <xp:this.script><![CDATA[var repeat = dojo.byId('#{id:repeat1}');
var list = repeat.getElementsByTagName('input');

for(x in list)
{
   if(list[x].type == "checkbox")
   {
       list[x].disabled = true;
   }
} ]]></xp:this.script>
        </xp:eventHandler></xp:button>
    <xp:br></xp:br><xp:repeat id="repeat1" rows="30" first="0" indexVar="index">

        <xp:this.value><![CDATA[#{javascript:return [0,1,2];}]]></xp:this.value>

        <xp:br></xp:br>

        <xp:text escape="true" id="computedField1">
            <xp:this.value><![CDATA[#{javascript:return "Repeat no: "+index;}]]></xp:this.value>
        </xp:text>
        <xp:br></xp:br><xp:button id="button4">
        <xp:this.value><![CDATA[#{javascript:return "Button Inside Repeat no: "+index;}]]></xp:this.value>
        <xp:eventHandler event="onclick" submit="false">
            <xp:this.script><![CDATA[var repeat = dojo.byId('#{id:repeat2}');
var list = repeat.getElementsByTagName('input');

for(x in list)
{
   if(list[x].type == "checkbox")
   {
       list[x].disabled = true;
   }
} ]]></xp:this.script>
        </xp:eventHandler></xp:button>
        <xp:repeat id="repeat2" rows="30" indexVar="index2">
            <xp:this.value><![CDATA[#{javascript:return [0,1,2,3,4,5,6];}]]></xp:this.value>
            <xp:checkBox text="#{javascript:return index2;}" id="checkBox1">


                <xp:eventHandler event="onchange" submit="false">
                    <xp:this.script><![CDATA[var repeat = dojo.byId('#{id:repeat2}');
var list = repeat.getElementsByTagName('input');

for(x in list)
{
   if(list[x].type == "checkbox")
   {
       list[x].disabled = true;
   }
} ]]></xp:this.script>
                </xp:eventHandler>

            </xp:checkBox>
            <xp:br></xp:br>
        </xp:repeat>
    </xp:repeat>

</xp:view>
 

FORUM PLAN UPDATE
Date revision: This forum will remain open to new posts and responses until December 1, 2018. (After that date, you will still be able to view and search the forum.) Also, we're taking a second look at the best place to host future conversation. For now, keep using this forum, and stay tuned for more news.