I have a profile settings page where users can change their password and they have to confirm it if they do. I cannot make this a required field, since they dont HAVE to change the password. Is there an example to validate the confirm password IF the password field is not empty? And then to check if they are equal? I was not able to find any such example…
Share
Add the following to your form’s
cleanmethod:EDIT
The validation error message above will go into
non_field_errors. You didn’t specify what error message is showing on each password field, but based on context, I would imagine it’s a “This field is required” message. If that’s the case, make sure that your form fields haverequired=Falsewhen you define them, or if you’re working with a form subclass (and can’t edit the actual form fields) you can override the__init__method of the form: