Conversation
There is an option "hiddenLabel" for a form field. But instead of "hiding" the label it doesn't render the label at all. This causes accessibility issues because every form field input must have an associated label.
This PR changes it so that instead of the label not being rendered at all it is rendered with a class of sr-only instead.
### Testing
Add the following field to any form
`
<field
name="test"
type="text"
label="Hidden"
hiddenLabel="true"
/>
'
Before and After applying the PR there will be no visual change BUT if you view the source you will see that the code has changed
### Before
`
<div class="control-group">
<div class="controls">
<input type="text" name="jform[test]" id="jform_test" value="" class="form-control">
</div>
</div>
`
### After
`
<div class="control-group">
<div class="control-label sr-only">
<label id="jform_test-lbl" for="jform_test">Hidden</label>
</div>
<div class="controls has-success">
<input type="text" name="jform[test]" id="jform_test" value="" class="form-control valid form-control-success" aria-invalid="false">
</div>
</div>
`
layouts/joomla/form/renderfield.php
Outdated
| $class = empty($options['class']) ? '' : ' ' . $options['class']; | ||
| $rel = empty($options['rel']) ? '' : ' ' . $options['rel']; | ||
| $id = $name . '-desc'; | ||
| $hide = empty($options['hiddenLabel']) ? '' : ' ' . "sr-only"; |
There was a problem hiding this comment.
@brianteeman What happens if someone adds a field where the hiddenLabel option is not empty but false: hiddenLabel="false"?
I think your code right now would also set the sr-only class in that case.
There was a problem hiding this comment.
Hmm, on the other hand I see it is like that without your PR, too.
There was a problem hiding this comment.
you wanna fix that, too? or wanna leave this pr as it is and i shall test?
|
I have tested this item ✅ successfully on f855283 This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/25085. |
Co-Authored-By: Quy <quy@fluxbb.org>
|
I have tested this item ✅ successfully on de6db06 This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/25085. |
1 similar comment
|
I have tested this item ✅ successfully on de6db06 This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/25085. |
|
RTC This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/25085. |
Co-Authored-By: Quy <quy@fluxbb.org>
|
I have tested this item ✅ successfully on faa2a56 This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/25085. |
|
Added docs required because technically we have a b/c break here requiring the label on hiddenLabel fields (I think the chances are low anyone's doing that but anyhow...) |
|
Thanks |
There is an option "hiddenLabel" for a form field. But instead of "hiding" the label it doesn't render the label at all. This causes accessibility issues because every form field input must have an associated label.
This PR changes it so that instead of the label not being rendered at all it is rendered with a class of sr-only instead.
Testing
Add the following field to any form
Before and After applying the PR there will be no visual change BUT if you view the source you will see that the code has changed
Before
After