Entfernen Sie die rote Kontur auf Formularelemente, die Validierung in Drupal scheitern
-
02-10-2019 - |
Frage
Wenn ein Drupal Form Validierung fehlschlägt, ist es neu gezeichnet mit den Elementen, dass Fehler bei der Überprüfung in einem roten Rand umgeben. Drupal tut dies durch die error
Klasse der Eingabeelemente hinzufügen und specifing einen 2px roten Rahmen auf input.error Elementen in system.css
.
Ohne dieses Stylesheet zu ändern, wie kann ich den roten Rahmen auf einer speziellen Form nur entfernen, während das Standardverhalten der Website auf den Rest mit?
ich glaube, die Lösung erfordern könnte ein benutzerdefinierten theme_form_element
, aber ich kann nicht herausfinden, wie eine einzelne Form anpassen nur.
Beachten Sie, dass ich möchte, dies zu tun, ohne auf diese jQuery Trick zurückgreifen zu müssen (was funktioniert):
$("#edit-name").removeClass('error');
Lösung
You will need to remove the error class from the form items. This can be done by overwriting the theme functions, in theme_textfield
, theme_textarea
... (there is one for each type)
Take a look at $element['#attributes']['class']
which contains the error class.
EDIT
To do it for a specific form element or form you can use the #theme
attribute or either form or element you want to change the theming function for.
Andere Tipps
The easiest way is not to try to modify the markup Drupal is spotting out, but instead to change the styles assocaited with the error
class.
You can do that without modifying system.css. Simply add a new stylesheet in your theme (or using an existing one!). Use the Cascading nature of CSS to change the way elements with errors appear. Add something like:
.error {
border: 0;
}
... and you are done.
To target only one specific form, add another selector, like so:
#my-specific-form .error {
border: 0;
}