Search code examples
javascriptjquerycheckboxzk

In Zkoss selected checkbox is setDisabled(true) but i want visibility of checkbox and tick remain same


for(int i=0;i<list_id.size();i++)
            {
                count++;
                Listitem l1=new Listitem();
                org.zkoss.zul.Checkbox ccc=new org.zkoss.zul.Checkbox();
                l1.setParent(signlist);
                Listcell c1=new Listcell();
                Listcell c2=new Listcell();
                Listcell c3=new Listcell();
                c1.setParent(l1);
                c2.setParent(l1);
                c3.setParent(l1);
                c2.setLabel(""+count);
                c3.setLabel(getSignId(list_id.get(i),temp)); 
                ccc.setParent(c1);              
                ccc.setId(list_id.get(i)+":"+i+group_id);
                InputStream in =rs.getAsciiStream(2);
                StringWriter w = new StringWriter();
                IOUtils.copy(in, w);
                mapped_sign = w.toString();
                if(mapped_sign.contains("|"))
                {
                    list_Name=mapped_sign.split("\\|");
                    for(int k=0;k<list_Name.length;k++)
                    {
                        list_id_Check.add(list_Name[k]);
                    }
                    if(list_id_Check.contains(list_id.get(i)))
                    {
                        ccc.setChecked(true);
                    }
                }
                else
                {
                    if(list_id.get(i).equals(mapped_sign))
                    {
                        ccc.setChecked(true);
                    }
                }
                ccc.setDisabled(true);

            c3.setId(list_id.get(i)+":"+group_id);  
            }

when i apply setDisabled(true) then selected and unslected checkbox visibility goes to fade. i just want after applying setDisabled the visibility of checkbox and tick still remain same.


Solution

  • As far as I know, there is no ZK-specific way to do that.
    Nevertheless, you can use ordinary CSS (and maybe a custom checkbox sprite) to style your own checkboxes.

    Here is an example (CSS taken from https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Forms/Advanced_styling_for_HTML_forms)

    <zk>
      <window border="normal" title="hello">
        <style>
            :root input[type=checkbox] {
              /* original check box are push outside the viexport */
              position: absolute;
              left: -1000em;
            }
    
            :root input[type=checkbox] + label:before {
              content: "";
              display: inline-block;
              width  : 16px;
              height : 16px;
              margin : 0 .5em 0 0;
              background: url("https://developer.mozilla.org/files/4173/checkbox-sprite.png") no-repeat 0 0;
    
            /* The following is used to adjust the position of 
               the check boxes on the text baseline */
    
              vertical-align: bottom;
              position: relative;
              bottom: 2px;
            }
    
            :root input[type=checkbox]:checked + label:before {
              background-position: 0 -16px;
            }
    
    
    
        </style>
        <vlayout>
              <checkbox id='chk1' label='enabled' />
              <checkbox id='chk2' label='disabled unchecked' disabled='true' />
              <checkbox id='chk3' label='disabled checked' checked='true' disabled='true' />
        </vlayout>
    
      </window>
    </zk>
    

    Of course, you should not link to mozilla's sprite but supply your own.

    Here is a SO answer providing further links and examples: How to style checkbox using CSS?