PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Add CSS class to error messages

  1. charlesantoineidrac
    Member

    Hi there,

    How can I add some classes to the error messages, besides .gfield_error ?

    Posted 9 years ago on Friday April 19, 2013 | Permalink
  2. David Peralty

    As far as I know, you can't change this. Can you explain why it would be needed? Is .gfield_error not enough for some reason?

    Posted 9 years ago on Friday April 19, 2013 | Permalink
  3. Richard Vav
    Administrator

    Is there some reason you can't add your own customised CSS for the error class to your themes style sheet.

    The only other solution I can think off is that you could add additional classes using the jQuery addClass method, so the following example would add the class .mynewclass to any element that is assigned the class .gfield_error

    <script>
    $(document).ready(function(){
         $('.gfield_error').addClass('mynewclass');
    });
    </script>

    Regards,
    Richard

    Posted 9 years ago on Friday April 19, 2013 | Permalink
  4. charlesantoineidrac
    Member

    Ok thx !

    Best solution would of course to have a filter to do that...
    Hey Gravity Team, you already have a couple of filters to add css classes at fields and confirmation button, why not push this a bit further, and make sure every single CSS class added can be customized... A unique filter for all those would be a nice solution, we could have a sort of array mapping the elements and the class they will receive.

    By the way, there is quite a few websites talking about this issue already, so I guess I am not alone. And relying on client side code to have correct CSS classes is not that great.
    How can I officially add this to suggestion to the user wish list ?

    Posted 9 years ago on Monday April 22, 2013 | Permalink
  5. charlesantoineidrac
    Member

    Oh, and I forgot to answer to David:

    Many reasons to add some CSS classes... I guess the same ones that made your team add a filter to add some CSS class to other elements in the form.

    For it's:
    Avoiding big CSS duplicates
    Enabling twitter bootstrap classes

    Posted 9 years ago on Monday April 22, 2013 | Permalink