I would like to create widgets that add specific classes to the markup of elements when the corresponding field has errors.
I find it difficult to find information on how to check whether a field is associated with this message from the widget definition code.
At the moment, I have the following stub widget code (the last widget will use more complex markup).
from django import forms from django.utils.safestring import mark_safe class CustomTextWidget(forms.Widget): def render(self, name, value, attrs): field_has_errors=False
Can anyone shed some light on a reasonable way to fill in the field_has_errors Boolean here? (or perhaps suggest a better way to accomplish what I'm trying to do). Thanks in advance.
django django-forms django-widget
bitbutter
source share