I noticed two problems when using the Select (or other) widget with a required field:

  1. The required marker is not displayed
  2. 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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dboulet’s picture

There are two problems with the way that the title for the widget is handled, when the field is required:

  1. The container element has its title displayed, but is marked as not required
  2. The select element (checkboxes in my case) has its title removed, but is marked as 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'

Dave Reid’s picture

Status: Active » Needs review

Confirmed regression in the 2.18 release with required select_or_other form elements.

rich.3po’s picture

Also seeing this issue, in version 7.x-2.18

Patch in #1 solves the issue for me, thanks

ShaunDychko’s picture

Status: Needs review » Reviewed & tested by the community

Works for me too, thanks a lot!

Alauddin’s picture

#1 - patch by dboulet works..thank you

haydeniv’s picture

Status: Reviewed & tested by the community » Fixed

Committed:
2.x: 98d3760
3.x: 8b4c31c

and rolled a new release.

Thanks!

merzikain’s picture

Status: Needs work » Fixed
Issue tags: -Needs tests

Ignore this, I setup my own validator and wasn't handling the validation for no value properly.

TwoD’s picture

Status: Fixed » Needs work
FileSize
382 bytes

This 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.

TwoD’s picture

Status: Needs work » Needs review
dboulet’s picture

TwoD, 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.

haydeniv’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

This 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

TwoD’s picture

Status: Fixed » Needs work
Issue tags: +Needs tests

Hmm, 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.

haydeniv’s picture

@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.

thekevinday’s picture

The 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.

goldlilys’s picture

#8 solved this issue for me too. Thanks.

kaidjohnson’s picture

It 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!

kaidjohnson’s picture

Status: Needs work » Fixed

#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.

Automatically closed -- issue fixed for 2 weeks with no activity.

  • Commit 8b4c31c on 7.x-3.x, 8.x-3.x by haydeniv:
    Issue #2030249 by dboulet: Required fields are broken when using the...