13 de enero de 2011

Checkbox de tres estados sin imágenes en HTML (estado indeterminado)

Necesitábamos un checkbox de tres estados para una sección de nuestro sitio de Internet. El checkbox debería iniciar en el tercer estado al cargar la página. También, debería poderse regresar al tercer estado usando Javascript. Además, quería que se usara el control nativo de la plataforma en la que se consultara, por lo que no podía usar imágenes. Encontré el atributo indeterminate.
Al parecer, sólo se puede acceder a este atributo mediante Javascript.

<form>
   <input id="c" type="checkbox" checked="checked"/>
</form>
<script>
   document.getElementById('c').indeterminate = true;
</script>

En la página 614 del libro Dynamic HTML: The Definitive Reference se menciona que este atributo lo reconoce Microsoft Internet Explorer versión 4 en adelante (Danny Goodman, O'Reilly Media, Third Edition edition, ISBN-10: 0596527403, ISBN-13: 978-0596527402.)


El sitio MSDN de Microsoft dice:
The indeterminate property can be used to indicate whether the user has acted on a control. For example, setting the indeterminate to true causes the check box to appear checked and dimmed, indicating an indeterminate state. The value of the indeterminate property acts independently of the values of the checked and status properties. Creating an indeterminate state is different from disabling the control. Consequently, a check box in the indeterminate state can still receive the focus. When the user clicks an indeterminate control, the indeterminate state turns off and the checked state of the check box toggles. (http://msdn.microsoft.com/en-us/library/ms533894.aspx)
El Working Draft de HTML5 más reciente hasta el día de hoy dice:
If the element's indeterminate IDL attribute is set to true, then the control's selection should be obscured as if the control was in a third, indeterminate, state. The control is never a true tri-state control, even if the element's indeterminate IDL attribute is set to true. The indeterminate IDL attribute only gives the appearance of a third state (HTML5, A vocabulary and associated APIs for HTML and XHTML, W3C Working Draft 13 January 2011).
Libros que, espero, encuentres útiles (lista automática):

No hay comentarios.:

Publicar un comentario