HTML: Why is there no built-in support for limiting state changes in a block without turning it off?

In HTML, only text controls, such as a text field, text area, password box, have a read-only property. Why don't they support the checkbox / radio button?

I know that I can achieve this function with a script by setting onclick = "return false;". (I don’t need a workaround, I want to know only the reason for the lack of support to support this goal)

But my question is, is there any specific reason for not supporting reading only in the check-box / radio button even though it accepts input from the user.

EDIT 1: I found this one , but it does not answer my question. Why is there no way to limit a user to a state change without turning it off?

+6
source share
4 answers

HTML 4.01 allows readonly for input with no type restrictions at all. However, it seems that it is not implemented at all in browsers, perhaps because the developers did not really need it. In HTML5 CR, readonly explicitly prohibited for input type=checkbox and HTML5 CR (or some other “HTML5 specification” such as HTML 5.1 Nightly or WHATWG Living HTML), which is usually what developers use as a guideline in our days.

There were suggestions allowing this in HTML5, for example. a discussion in May 2011 on the whatwg list, as well as browser error reports (rejected based on what HTML5 says), but apparently without good enough use cases. Although there are real use cases, they are probably too marginal, and reasonable alternatives may be presented, such as using a flag image (checked or unchecked as desired) with appropriate appropriate text, and if the pseudo-flag is checked for verification, a hidden field containing the required information.

+2
source

Use jquery to disable it (read-only) or enable it. Only text fields allow you to read them during rendering.

 <input type="checkbox" id="chk1"/> 

then using jquery

 $(document).ready(function(){ $("#chk1").prop('disabled',true); }); 
+1
source

It is important to understand that READONLY simply prevents the user from changing the value of the field, and not from interacting with the field. For many field types, READONLY does not matter, because you usually do not change the value. For example, in the checkboxes you can check them on. or off (thus set the state to CHECKED), but you will not change the value of the field. DISABLED, however, actually prevents you from using this field.

Note that in these examples, you can check the boxes, even if they are read-only:

A SOURCE

EXAMPLE from faqs.org

+1
source

First, you should not cross the onclick event of a flag for the simple purpose of checking if it is checked. Instead, you should use the onchange event. What for? Since the onclick event is fired before the onchange event, so if you cross the onclick event, you won’t be able to get the actual state of the flag unless you do some ugly javascript acrobatics with setTimeout

If you want to select the read-only checkbox, you must use the disabled attribute. As below ...

 <input type="checkbox" disabled/> 

To answer your question, I think this is better explained by HTML Specs in W3.Org

The difference between disabled and readonly is that the read-only controls are still customizable, so the user can still select text and interact with it, while disabled controls are not fully interactive. (For this reason, only text controls can be read-only: for instances, there would be no point in checking boxes or buttons.)

0
source

Source: https://habr.com/ru/post/969561/


All Articles