Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Edit</strong></p> <p>Thanks to Janus Troelsen's comment, I found a better solution. </p> <h2><strong>HTML5 defines a property for checkboxes called <code>indeterminate</code></strong></h2> <p>See <a href="http://dev.w3.org/html5/markup/input.checkbox.html#input.checkbox-interface" rel="noreferrer">w3c reference guide</a>. To make checkbox appear visually indeterminate set it to true:</p> <pre><code>element.indeterminate = true; </code></pre> <p>Here is <a href="http://jsfiddle.net/b81nsu7p/" rel="noreferrer">Janus Troelsen's fiddle</a>. Note, however, that:</p> <ul> <li><p>The <code>indeterminate</code> state cannot be set in the HTML markup, it can only be done via Javascript (see this <a href="http://jsfiddle.net/uxTTd/" rel="noreferrer">JSfiddle test</a> and this <a href="http://css-tricks.com/indeterminate-checkboxes/" rel="noreferrer">detailed article in CSS tricks</a>)</p></li> <li><p>This state doesn't change the value of the checkbox, it is only a visual cue that masks the input's real state.</p></li> <li><p>Browser test: Worked for me in Chrome 22, Firefox 15, Opera 12 and back to IE7. Regarding mobile browsers, Android 2.0 browser and Safari mobile on iOS 3.1 don't have support for it.</p></li> </ul> <p><strong>Previous answer</strong></p> <p>Another alternative would be to play with the checkbox transparency for the "some selected" state (as Gmail <strike>does</strike> used to do in previous versions). It will require some javascript and a CSS class. Here I put a particular example that handles a list with checkable items and a checkbox that allows to select all/none of them. This checkbox shows a "some selected" state when some of the list items are selected.</p> <p>Given a checkbox with an ID <code>#select_all</code> and several checkboxes with a class <code>.select_one</code>,</p> <p>The CSS class that fades the "select all" checkbox would be the following:</p> <pre><code>.some_selected { opacity: 0.5; filter: alpha(opacity=50); } </code></pre> <p>And the JS code that handles the tri-state of the select all checkbox is the following:</p> <pre><code>$('#select_all').change (function () { //Check/uncheck all the list's checkboxes $('.select_one').attr('checked', $(this).is(':checked')); //Remove the faded state $(this).removeClass('some_selected'); }); $('.select_one').change (function () { if ($('.select_one:checked').length == 0) $('#select_all').removeClass('some_selected').attr('checked', false); else if ($('.select_one:not(:checked)').length == 0) $('#select_all').removeClass('some_selected').attr('checked', true); else $('#select_all').addClass('some_selected').attr('checked', true); }); </code></pre> <p>You can try it here: <a href="http://jsfiddle.net/98BMK/" rel="noreferrer">http://jsfiddle.net/98BMK/</a></p> <p>Hope that helps!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload