Problem/Motivation

The current HTML5 specification for the "disabled" and "readonly" attributes of form elements allows their values to be specified as either a boolean attribute or a string attribute. However, this has led to confusion and inconsistencies in implementation across various browsers and platforms.
To improve the clarity and standardization of the HTML5 specification, there is a need to redefine these attributes as purely boolean attributes. This change would ensure that these attributes are used uniformly across different web browsers and platforms, thereby enhancing the accessibility and usability of web forms for users.

The proposed adjustment aims to streamline the behavior of the "disabled" and "readonly" attributes, providing developers with a more consistent and predictable approach to implementing these attributes in their web forms. This modification would contribute to a more coherent and intuitive web development experience and facilitate a smoother user interaction with forms across various devices and platforms.

The code in FormBuilder::handleInputElement():

    if (!empty($element['#disabled'])) {
      if (!empty($element['#allow_focus'])) {
        $element['#attributes']['readonly'] = 'readonly';
      }
      else {
        $element['#attributes']['disabled'] = 'disabled';
      }
    }

Steps to reproduce

Identify the FormBuilder class in the codebase.

Locate the handleInputElement method within the FormBuilder class. Ensure you have access to the source code for this method.

Proposed resolution

Update the HTML5 specification to define the "disabled" and "readonly" attributes as boolean attributes only.

These should actually be boolean attributes:

    if (!empty($element['#disabled'])) {
      if (!empty($element['#allow_focus'])) {
        $element['#attributes']['readonly'] = TRUE;
      }
      else {
        $element['#attributes']['disabled'] = TRUE;
      }
    }

Remaining tasks

Review

User interface changes

API changes

Data model changes

Release notes snippet

Issue fork drupal-3388071

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Dave Reid created an issue. See original summary.

dave reid’s picture

Issue tags: +html5

adrian_s_m’s picture

Version: 11.x-dev » 10.1.x-dev
Status: Active » Needs review
StatusFileSize
new732 bytes

Adding patch file, only for 10.1.x.

smustgrave’s picture

Version: 10.1.x-dev » 11.x-dev
Status: Needs review » Needs work
Issue tags: +Needs tests, +Needs issue summary update

MR 4816 is pointing to correct branch. 11.x is the current development branch of core.

If you need a hard link for 10.1 it's fine to post that but would leave a comment that it's just for 10.1

As a bug will need a test case showing the issue.
Also issue summary appears incomplete with missing parts.

adrian_s_m’s picture

StatusFileSize
new727 bytes

Uploading new file patch, since I set the boolean value to a string previously. This is needed for 10.1.x

arisen’s picture

Status: Needs work » Needs review
StatusFileSize
new1.56 KB

Fixed the failing tests. Uploading the patch. Please review.

poker10’s picture

Category: Bug report » Task
Status: Needs review » Needs work

The attributes in the current form (disabled="disabled" / readonly="readonly") seems to be valid in HTML5, see: https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#boolean... .

They are boolean attributes and according to the specs:

2.3.2 Boolean attributes

A number of attributes are boolean attributes. The presence of a boolean attribute on an element represents the true value, and the absence of the attribute represents the false value.

If the attribute is present, its value must either be the empty string or a value that is an ASCII case-insensitive match for the attribute's canonical name, with no leading or trailing whitespace.

So this does not looks like a bug.

The patch #7 will change the output of such an attribute from:
<input disabled="disabled">
to:
<input disabled="">

If I read the specs correctly, both seems to be valid in HTML5 and looks pretty equivalent for me.

If we can achieve to have just: <input disabled> , then it can be a bit cleaner, but not sure if this can be achieved easily. Other option is to close this as Works as designed. Thanks!

aditi saraf’s picture

Status: Needs work » Needs review
StatusFileSize
new729 bytes
aditi saraf’s picture

StatusFileSize
new4.34 KB
new4.34 KB
smustgrave’s picture

Status: Needs review » Needs work

@Aditi Saraf thank you for the interest in this but this was tagged for tests and issue summary update. When moving to review please read the comments and tags to make sure it's actually ready for review

aditi saraf’s picture

@smustgrave thanks for your valuable suggestion . I will look into this .

aditi saraf’s picture

Issue summary: View changes
aditi saraf’s picture

Issue summary: View changes
aditi saraf’s picture

Issue summary: View changes
Status: Needs work » Needs review

Hi @smustgrave i have updated issue summary . and applied patch and interdiff #10 .

poker10’s picture

Status: Needs review » Needs work

Thanks.

The patches #9 and #10 are not working and the approach seems to be incorrect. They are setting the disabled attribute to FALSE, which is wrong and not valid HTML5. I am hiding these patches and moving back to NW.

My concerns from #8 are still valid, so please do not upload new patches which are only changing the string attribute values to boolean values.

prudloff made their first commit to this issue’s fork.

prudloff’s picture

Status: Needs work » Needs review

Rebased and fixed failing tests.

If we can achieve to have just: <input disabled> , then it can be a bit cleaner, but not sure if this can be achieved easily. Other option is to close this as Works as designed. Thanks!

Maybe something changed in core but I tested this and boolean attributes are displayed like you suggest.

smustgrave’s picture

Issue summary: View changes
Status: Needs review » Needs work
Issue tags: -Needs tests, -Needs issue summary update +Needs Review Queue Initiative

Ran test only job here https://git.drupalcode.org/issue/drupal-3388071/-/jobs/5713517 but it passes, so are the test changes needed?

If you are another contributor eager to jump in, please allow the previous poster(s) at least 48 hours to respond to feedback first, so they have the opportunity to finish what they started!

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.