Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I noticed two problems when using the Select (or other) widget with a required field:
- The required marker is not displayed
- There is no error message displayed when field validation fails
There needs to be a few changes to the way that the widget is processed, I’ll submit a patch.
Comment | File | Size | Author |
---|---|---|---|
#8 | 2030249.8.patch | 382 bytes | TwoD |
#1 | select_or_other_required-2030249-1.patch | 1 KB | dboulet |
Comments
Comment #1
dboulet CreditAttribution: dboulet commentedThere are two problems with the way that the title for the widget is handled, when the field is required:
This means that the required marker is not displayed because the visible title belongs to the container element which is technically not required. Also, the validation message is not shown because the required select element has no title and can’t be named in the error message.
My proposed solution is to preserve the title for the select element itself and hide the container element’s title, see attached patch.
See related issue: #1736636: If it's required field and other is selected but not filled in the error reports with blank field title, message is 'required'
Comment #2
Dave ReidConfirmed regression in the 2.18 release with required select_or_other form elements.
Comment #3
rich.3po CreditAttribution: rich.3po commentedAlso seeing this issue, in version 7.x-2.18
Patch in #1 solves the issue for me, thanks
Comment #4
ShaunDychko CreditAttribution: ShaunDychko commentedWorks for me too, thanks a lot!
Comment #5
Alauddin CreditAttribution: Alauddin commented#1 - patch by dboulet works..thank you
Comment #6
haydeniv CreditAttribution: haydeniv commentedCommitted:
2.x: 98d3760
3.x: 8b4c31c
and rolled a new release.
Thanks!
Comment #7
merzikain CreditAttribution: merzikain commentedIgnore this, I setup my own validator and wasn't handling the validation for no value properly.
Comment #8
TwoDThis commit borked the title display for checkboxes and radios, it's always invisible now. Setting #title_display to "invisible" is recursive in a way, since it just sets a class, and the stylesheets target any label with that class in a a parent.
Why not simply set $element['title'] = NULL? The sub-field already have a correct title? Works great for me.
@merzikain, it already fails validation if the "other" field is empty.
Comment #9
TwoDComment #10
dboulet CreditAttribution: dboulet commentedTwoD, by default the .element-invisible class is added directly to the parent label element—this shouldn’t affect any other labels. Maybe your theme treats it differently?
In any case, setting the parent element’s title to NULL should be ok, I think.
Comment #11
haydeniv CreditAttribution: haydeniv commentedThis back and forth has gone on long enough with this widget. Every time we commit something, we break something else. No more commits until we get test coverage.
#1969084: #Meta Automated tests
Comment #12
TwoDHmm, I was using this in a webform, and just noticed it does most/all the select_or_other integration on its own, which is a bit of a WTF since it's missing several options controlling the "other" field... That's probably where my problems begin.
Comment #13
haydeniv CreditAttribution: haydeniv commented@TwoD Can you open a separate issue for yours as this one is dealing with the Field API widget and yours is the webform widget? Thanks.
Comment #14
thekevinday CreditAttribution: thekevinday commentedThe patch from #8 solves the issue.
For me, this is an accessibility issue in that when the title is defined, it gets assigned a 'for='some_field'.
When that field does not exist, then we have an accessibility problem.
Setting the title to NULL prevents the parent label from being created.
Comment #15
goldlilys CreditAttribution: goldlilys commented#8 solved this issue for me too. Thanks.
Comment #16
kaidjohnson CreditAttribution: kaidjohnson commentedIt makes no sense to attempt to retain the wrapper title if that title is being copied down to the ['select'] element anyway, so removing the wrapper title altogether is the ideal solution. +1 for #8 - worked perfectly.
Thanks!
Comment #17
kaidjohnson CreditAttribution: kaidjohnson commented#8 is technically a patch that resolves #2072857: Webform component's Label and Description do not display in select_or_other-2.19 -- I'm moving the patch over to there per @haydeniv's request in #13 and updating that post's status to needs review. Closing this one as fixed, as the patch has already been committed to the project.