Problem:
Empty title/label on validating multiple value text area field.
Screenshots:

Clean Drupal 7.24 installation with an Article content type and Questions (multiple values) field as Long text with Text area widget

You can see here the title is missing in validation error for Questions field.
Bug:
As you can see in the second image, the title is missing if you have multiple values. I debugged the _form_validate function where I see that it's trying to get the #title from each item of a field in $elements array. But the title is empty for those items.
Drupal 8:
Drupal 8 is using different UX for validation so this bug is not an issue for Drupal 8.
Comments
Comment #1
alesr commentedComment #2
alesr commentedThis is the code from _form_validate function in form.inc file where the problem is.
Those items in multiple values long text field all have $elements['#title'] set, but it is empty. Actually one (cheap) solution is to check if !empty() together with isset().
A patch is attached to nudge the bot.
Comment #3
ianthomas_ukThis bug happens because we validate each of the multi-value items separately, so while the field itself has a title, each of the child elements doesn't. The patch on #2 hides the error message when this happens, rather than showing the incorrect error message.
This isn't really a great solution, as we still want to tell the user which field they need to complete. There's another error message that needs the field title higher up the function (line 1307) that does work. I suggest we get the title for missing required fields in the same way.
Comment #4
alesr commentedHere is the patch that is showing the field name as it is solved above in the code.
Still not the title/label that we would like to have, but much better than no title at all.
Comment #5
ianthomas_ukThat's better, but I think while we're at it we should include $elements['#parents'][0] in the if statement, as we can now display a useful message if that is set.
Having said that, is $elements['#parents'][0] ever not set? Everywhere else in the function assumes that either $elements['#title'] or $elements['#parents'][0] will be set, so should we just do the same here? (i.e. remove the if/else and just have the new contents of the if).
Comment #6
oleg.medvedev commentedComment #7
oleg.medvedev commentedComment #9
oleg.medvedev commentedComment #10
Rostislav Sergeenkov commentedAlternative idea is to add title to the 1-st item of multiple value field (since only the 1-st element from required field is validated and must not be empty) and hide it using $element['#title_display'] = 'invisible'. As a result field name appears in validation message. See patch and attached before_patching.png and after_patching.png
Comment #12
Rostislav Sergeenkov commentedComment #13
dcam commentedStarting Testbot.
Comment #14
pkht commentedI had this exact issue in my current project.
Patch #12 solves it.
I've also tested it in a fresh install - success.
Comment #15
David_Rothstein commentedThis issue is reproducible in Drupal 8.
You do need to fill in the title field (to avoid the HTML5 client-side validation), which is different than the screenshot shown in the issue summary, but otherwise the steps to reproduce are essentially the same as for Drupal 7.
(And of course, Drupal 8 has server-side validation even on fields for which the client-side validation is enabled by default... so even if the HTML5 validation intercepted the error for this field too, it would still need to be fixed. But I'm able to reproduce it just fine without even turning that off.)
Comment #16
brunodboLooks like this is fixed in D8 now. On a fresh D8 install, I disabled the HTML5 validation for the article form (by adding
novalidate="novalidate"to the form element), and the validation message for a multivalue text field now includes the field name (and the value as well) - see attached screenshot.The patch in #12 fixes the issue for me in D7.
Comment #17
brunodboAnd here is the aforementioned screenshot.
Comment #18
brunodboTriggering testbot.
Comment #20
David_Rothstein commentedLooks like #980144: Issues with "required, multiple" fields in forms fixed this for Drupal 8, and a backport to Drupal 7 is in progress there. That issue is older and the patch there looks farther along, so I'm closing this as a duplicate.