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.
It can often be helpful to have an error class on the top level div for a given form element (for example, if you have an icon implemented as a background you may want to change the icon on error), so I whipped up a quick and dirty patch to do just that.
It seems to work okay. For checkboxes and radios, you have to go up a few parents to reach the right div, and there may be a better way to do that - I'm open to suggestions.
Comment | File | Size | Author |
---|---|---|---|
#4 | 1710368-parent-error-4.patch | 1.88 KB | whthat |
Comments
Comment #1
attiks CreditAttribution: attiks commentedI like the idea, but it needs some more work
Moving to 7.x-dev
whitespace
rename parent to $parent, so we see it's a jQuery object.
better:
$element = $(element);
element.hasClass
this is very tricky, if the output is using other wrappers.
Comment #2
leanderl CreditAttribution: leanderl commentedHere's a method I've come up with to solve this short term in my webform. I have added an extra .check-icon span to my input fields through theme_textfield() and theme_webform_email() and then I put this in my themes custom js-file.
This solution is of course yet incomplete, I have to add selects and radios and also create something to remove "valid" from the .check-icon if the field is no longer valid.
Comment #3
leanderl CreditAttribution: leanderl commentedOk, so my previous approach didn't work out. But a good solution is right here: http://drupal.org/node/1798690
Works perfectly and beautifully for "positive feedback check icon".
Comment #4
whthat CreditAttribution: whthat at College of Western Idaho commentedRerolling against the latest:
By default this will add an error class to a div, which can trigger some fun backgrounds from drupal core but the style easily overridden. We are using this: