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
| Comment | File | Size | Author |
|---|
Issue fork drupal-3388071
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
Comment #2
dave reidComment #4
adrian_s_m commentedAdding patch file, only for 10.1.x.
Comment #5
smustgrave commentedMR 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.
Comment #6
adrian_s_m commentedUploading new file patch, since I set the boolean value to a string previously. This is needed for 10.1.x
Comment #7
arisenFixed the failing tests. Uploading the patch. Please review.
Comment #8
poker10 commentedThe 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:
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!Comment #9
aditi saraf commentedComment #10
aditi saraf commentedComment #11
smustgrave commented@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
Comment #12
aditi saraf commented@smustgrave thanks for your valuable suggestion . I will look into this .
Comment #13
aditi saraf commentedComment #14
aditi saraf commentedComment #15
aditi saraf commentedHi @smustgrave i have updated issue summary . and applied patch and interdiff #10 .
Comment #16
poker10 commentedThanks.
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.
Comment #18
prudloff commentedRebased and fixed failing tests.
Maybe something changed in core but I tested this and boolean attributes are displayed like you suggest.
Comment #19
smustgrave commentedRan 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!