Menu

#228 display partial selection in Checkbox Groups

v10
open
3
2015-11-14
2015-11-09
No

Jmol.setCheckboxGroup() involves defining groups of leader+follower checkboxes.
Plan: to implement a visual indicator of partial selection, i.e the leader is "partially checked" when some of its followers are checked, others not.
There is now support for this via the HTML5 "indeterminate" property.
See e.g.
https://css-tricks.com/indeterminate-checkboxes/
http://jsfiddle.net/5tpXc/

Discussion

  • Angel Herraez

    Angel Herraez - 2015-11-12

    I have the solution, in js/JSmolControls.js
    but yet I don't know where in the source it should go

    c._cbNotifyMaster = function(m){
        //called when a group item is checked
        var allOn = true;
        var allOff = true;
        for (var chkBox in m.chkGroup){
            if(m.chkGroup[chkBox].checked)
                allOff = false;
            else
                allOn = false;
        }
        // AH
        m.chkMaster.indeterminate = false;
        if (allOn) { m.chkMaster.checked = true; }
        else if (allOff) { m.chkMaster.checked = false; }
        else { m.chkMaster.indeterminate = true; }
        // end AH
        if ((allOn || allOff) && c._checkboxItems[m.chkMaster.id])
            c._cbNotifyMaster(c._checkboxItems[m.chkMaster.id])
    }
    

    It only works one level deep (i.e. for the parent leader but not for the grandparent leader checkbox).
    Note the visual aspect of the 'indeterminate' checkbox is set by the browser GUI (and quite differently style among browsers).

     
  • Angel Herraez

    Angel Herraez - 2015-11-13

    I'm working on the fix that will recurse to upper-level leaders and make them indeterminate if needed. I think I've got it solved. More soon...

     
  • Angel Herraez

    Angel Herraez - 2015-11-13

    This is working now. See http://biomodel.uah.es/JSmol/test_cbGroup.htm
    It still needs to be implemented in the source of js/JSmolControls.js for a future release.

    c.cbNotifyMaster = function(m){
            //called when a group item is checked
            var allOn = true;
            var allOff = true;
            var mixed = false;
            for (var chkBox in m.chkGroup){
                if (m.chkGroup[chkBox].checked) {
                    allOff = false;
                } else {
                    allOn = false;
                }
                if (m.chkGroup[chkBox].indeterminate) {
                    mixed = true;
                }
            }
    
            if (allOn) { m.chkMaster.checked = true;  }
            else if (allOff) { m.chkMaster.checked = false;  }
            else { mixed = true; }
            m.chkMaster.indeterminate = mixed;
            if (c.checkboxItems[m.chkMaster.id]) {
                c.cbNotifyMaster(c.checkboxItems[m.chkMaster.id])
            }
        }
    
     

    Last edit: Angel Herraez 2015-11-13

Log in to post a comment.

MongoDB Logo MongoDB