W3C home > Mailing lists > Public > whatwg@whatwg.org > April 2011

[whatwg] Can we make checkboxes readonly?

From: David McMurray <david@davidmcmurray.net>
Date: Thu, 7 Apr 2011 13:10:35 +0100
Message-ID: <BANLkTi=xxgZbme8XreUe_k=9rZKFTXL8jg@mail.gmail.com>
On 6 April 2011 23:39, Lachlan Hunt <lachlan.hunt at lachy.id.au> wrote:

> On 2011-04-07 00:28, Tab Atkins Jr. wrote:
>
>> On Wed, Apr 6, 2011 at 3:12 PM, Lachlan Hunt<lachlan.hunt at lachy.id.au>
>>  wrote:
>>
>>> What's wrong with using disabled?
>>>
>>>
>>> <input type="checkbox" disabled>
>>> <input type="checkbox" disabled checked>
>>>
>>
>> Disabled elements don't participate in form submission.
>>
>
> That's true, but if the controls are readonly, then the user can't change
> the value and so why does that matter?  Could you clarify the use case for
> having a readonly checkbox value submitted?
>

A lot of my work involves tables of data which can be navigated via a
highlighted cell much like a spreadsheet. Where some cells may be readonly
within the table itself, but perhaps editable through a popup value picker
opened by double clicking on the cell for example. In this case the text
input or checkbox would need to be readonly but still provide a value
through the form on submission. This may not sound appropriate for a
checkbox because there are only two options, but consider if you had a Y/N
field but if the Y option is chosen you wanted to record some other data in
a hidden field because you didn't want it to appear in the table. For
example you might have a field indicating whether a client wishes to be
contacted via telephone, you might then have a popup value picker appear
when clicking on the checkbox with 3 options 'No', 'Yes, contact anytime' or
'Yes, only during office hours'. The popup would cause the checkbox to be
cleared if the first option is selected, and checked for the other two and a
hidden field may be used to store the contact time preference.

I would like to add that it would also be advantageous if checkboxes could
be made readonly and in doing so follow readonly text inputs with regards to
responding to and firing events like focus, blur, click etc.

This has been a source of much frustration when trying to implement a
spreadsheet-like table where onfocus, onblur and onclick events are used to
highlight or unhighlight a cell, because disabled checkboxes do not respond
to nor fire these events. Some consistency here with other input types like
textbox would be very much appreciated.

David McMurray
Received on Thursday, 7 April 2011 05:10:35 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 30 January 2013 18:48:03 GMT