Remove the red outline of form elements that do not validate validation in drupal

When the drupal form fails validation, it redraws with elements that fail validation, surrounded by a red border. Drupal does this by adding the error class to the input elements and pointing to the red 2px border on the input.error elements in system.css .

Without changing this stylesheet, how can I remove the red border for a specific form only using the default behavior on the rest of the site?

I believe that a solution may require the use of a custom theme_form_element , but I cannot figure out how to configure only one form.

Note that I would like to do this without resorting to the jQuery trick (which works):

 $("#edit-name").removeClass('error'); 
+4
source share
2 answers

You will need to remove the error class from the form elements. This can be done by overwriting the theme functions in theme_textfield , theme_textarea ... (there is one for each type)

Take a look at the $element['#attributes']['class'] , which contains the error class.

EDIT
To do this for an element or form of a specific form, you can use the #theme attribute or any form or element that you want to change for the theming function.

+2
source

The easiest way is not to try to change the Drupal markup, but instead to change the styles associated with the error class.

You can do this without modifying system.css. Just add new styles to 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're done.

To customize only one specific form, add another selector, for example:

 #my-specific-form .error { border: 0; } 
0
source

Source: https://habr.com/ru/post/1308484/


All Articles