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 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?
Comment | File | Size | Author |
---|---|---|---|
drupal.form-required-custom-error.0.patch | 4.1 KB | sun | |
Comments
Comment #1
sunComment #2
Damien Tournoud CreditAttribution: Damien Tournoud commentedAFAIK, that never was possible. There can be only one error message per element, and the first one wins.
Comment #3
sunHm, 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:
"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...
Comment #4
Bojhan CreditAttribution: Bojhan commentedInteresting 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.
Comment #6
sunhttp://drupal.org/node/742344 seems to be the only viable resolution at this point.