Attribute #allow_focus used for creating readonly fields is not documented

Created on 30 October 2015, over 9 years ago
Updated 26 March 2025, 14 days ago

API page: https://api.drupal.org/api/drupal/developer%21topics%21forms_api_referen...

It is not documented, that setting #allow_focus to TRUE on an element which has #disabled set to TRUE will make it readonly in HTML instead of disabled.
It is crucial for providing fields that do not allow user input but can be selected with most browsers. See related issue.

FF recommends setting readonly instead of disabled for elements that should be copyable. The Drupal Form API documentation doesn't show the way to do it (manually setting the #attributes tag to have the readonly element instead of using disabled would bypass Drupal's security checks that do not allow disabled elements to be returned with modified data - this is on line 2075 of form.inc in Drupal 7.39). However, I could find in the code that setting #allow_focus on a #disabled element would make it readonly (form.inc line 2060), so this is the correct way of doing it, but it's not yet documented on the Form API page.

🐛 Bug report
Status

Closed: won't fix

Component

API documentation files

Created by

🇭🇺Hungary banviktor

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024