-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FAPI: Document that the '#disabled' property in the FAPI is not a 1-1 equivalent of the respective HTML property #132
Comments
...should we introduce a pseudo-section in the FAPI documentation, to explain that |
...relevant code: https://github.com/backdrop/backdrop/blob/1.x/core/includes/form.inc#L2109 // Setting #disabled to TRUE results in user input being ignored, regardless
// of how the element is themed or whether JavaScript is used to change the
// control's attributes. However, it's good UI to let the user know that input
// is not wanted for the control. HTML supports two attributes for this:
// http://www.w3.org/TR/html401/interact/forms.html#h-17.12. If a form wants
// to start a control off with one of these attributes for UI purposes only,
// but still allow input to be processed if it's sumitted, it can set the
// desired attribute in #attributes directly rather than using #disabled.
// However, developers should think carefully about the accessibility
// implications of doing so: if the form expects input to be enterable under
// some condition triggered by JavaScript, how would someone who has
// JavaScript disabled trigger that condition? Instead, developers should
// consider whether a multi-step form would be more appropriate (#disabled can
// be changed from step to step). If one still decides to use JavaScript to
// affect when a control is enabled, then it is best for accessibility for the
// control to be enabled in the HTML, and disabled by JavaScript on document
// ready.
if (!empty($element['#disabled'])) {
if (!empty($element['#allow_focus'])) {
$element['#attributes']['readonly'] = 'readonly';
}
else {
$element['#attributes']['disabled'] = 'disabled';
}
} |
Pinging @bugfolder re this one. Curious to see what you think. |
https://docs.backdropcms.org/form_api#disabled currently says:
However, a more extensive explanation, such as the comment above, would be helpful in the FAPI property description. It seems likely that more people would learn the subtleties from the FAPI docs than will go browse the
If by "pseudo-section" you mean create an entry for I'll do some editing/addition there, then ping here for people to review and/or suggest further edits. |
FAPI already had the In terms of adding further explanation, though, I ran into some puzzling behavior. I was going to focus the discussion on "what properties do you set to get desired outcomes", rather than a detailed discussion of underlying theory and standards (like the code comments). So I set up some test checkboxes with all possible combinations of the properties And here's what the submitted values were: So, there's a bunch of puzzling issues with the current Backdrop core behavior, and before I start trying to describe this in the docs, I will ask the question if all this is really what's intended?
Here, for reference, is the test form code:
|
I put together a table summarizing the outcome of the form elements in the previous comment: The key points that should presumably be documented in the
I think that's a accurate description of the current behavior. Is it what the current behavior actually ought to be? In particular, I would have thought that based on the statement above,
that any element that is |
This is related to #69, backdrop/backdrop-issues#4083 and backdrop/backdrop-issues#2615 (comment)
I've been working with the FAPI for years now, yet this has just been a revelation to me:
'#disabled'
attribute'#readonly'
attribute - and that's by design.['#attributes']['disabled'] = 'disabled'
.['#attributes']['readonly'] = 'readonly'
.Now read https://stackoverflow.com/questions/7730695/whats-the-difference-between-disabled-disabled-and-readonly-readonly-for-ht (keep in mind that this is HTML-specific - NOT Backdrop/Drupal FAPI-specific). The gist of it is this:
The problem is that most (all?) developers working with Backdrop/Drupal expect
'#disabled'
to be behaving as['#attributes']['disabled'] = 'readonly'
("lock" the form element so that its value cannot be changed, but still allow the value to be sent on form submit), when in fact it doesn't.I think that we should document all that in https://docs.backdropcms.org/form_api#disabled
We should also document everything mentioned in: https://www.drupal.org/project/drupal/issues/500868#comment-2833796
The text was updated successfully, but these errors were encountered: