I don't get it.

As attached patch proves, I'm entirely unable to set custom validation errors for #required form elements.

Am I just nuts or was this possible before?

CommentFileSizeAuthor
drupal.form-required-custom-error.0.patch4.1 KBsun
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sun’s picture

Assigned: Unassigned » sun
Damien Tournoud’s picture

AFAIK, that never was possible. There can be only one error message per element, and the first one wins.

sun’s picture

Hm, I see. http://api.drupal.org/api/function/form_set_error/7 being guilty.

Now I'm not sure how I'm supposed to visually indicate that a form element is required, but cannot use #required, because the form element's label does not work in the auto-generated error message "!title field is required.", like here:

Bogus #required error message

"Analyze for field is required." totally doesn't work as error message, but the UX team agrees with those form element labels.

Due to recent form validation changes, I know that I'm able to dynamically enable #required in a form validation handler, since form validation handlers can alter the form like #process callbacks now. That allows to visually indicate required fields after submitting the form.

However, I don't see a meaningful way to add a visual required marker for the initial form build, unless I'd start to fiddle with #pre_render.

Hm. Technically, it seems like #742344: Allow forms to set custom validation error messages on required fields would solve at least this single use-case...

Bojhan’s picture

Interesting we only have visual error elements for text input form elements? Still people should be allowed to make custom error messages if it can provide more guidance.

Status: Needs review » Needs work

The last submitted patch, drupal.form-required-custom-error.0.patch, failed testing.

sun’s picture

Status: Needs work » Closed (duplicate)

http://drupal.org/node/742344 seems to be the only viable resolution at this point.