Hi Lucas, In the case that you want to apply an error to a specific field, there's the add_error method (docs: https://docs.djangoproject.com/en/2.2/ref/forms/api/#django.forms.Form.add_error ).
For your example (untested): def clean(self): cleaned_data = super().clean() password = cleaned_data.get('password') password_confirm = cleaned_data.get('password_confirm') if password and not password_confirm: self.add_error('password_confirm', self.fields['password_confirm'].error_messages['required']) return cleaned_data Yes this isn't quite as concise as saying "reuse the required message from the field." However I think adding the shortcut path would still be too complex. Django has 69 open tickets on forms: https://code.djangoproject.com/query?status=assigned&status=new&component=Forms&col=id&col=summary&col=status&col=owner&col=type&col=component&col=version&desc=1&order=id Whilst skimming them I noticed one which might intersects this discussion (though there may be others) - the addition of multi-field validators: https://code.djangoproject.com/attachment/ticket/12498/complex-validator-docs.diff . Given they carry error messages, maybe some work around that would make forms easier in the way you imagine? Thanks, Adam On Fri, 6 Sep 2019 at 17:23, Lucas Weyne <weynelu...@gmail.com> wrote: > Hi Adam, > > Your refactor works great and thats how I was thinking to solve this > problem. My idea its was use the Meta.error_messages dictionary to solve > default error messages. > > What if I want to raise a ValidationError for a conditional required field > and display the default required message *This field is required.*? > I can't see another wat to raise a default error message like required, > blank, invalid, unique_together without pass the message again. > > > def clean(): > cleaned_data = super().clean() > password = cleaned_data.get('password') > password_confirm = cleaned_data.get('password_confirm') > > if password and not password_confirm: > # Raise the required validation error (with default message > 'This field is required') > self.fail('password_confirm', 'required') > > return cleaned_data > > The example problem is a password confirmation, but can be any type of > field that can be required based on another field > > -- > You received this message because you are subscribed to the Google Groups > "Django developers (Contributions to Django itself)" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to django-developers+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-developers/46b4fa99-c060-4ba2-9bc2-9ef3b6a822bc%40googlegroups.com > <https://groups.google.com/d/msgid/django-developers/46b4fa99-c060-4ba2-9bc2-9ef3b6a822bc%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- Adam -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CAMyDDM3CktPn6VGQ5hGKX5YPN%3D_977c60yxq_fNjYWFNE-LW3A%40mail.gmail.com.