[Answer]-Validation when displaying already existing element

1đź‘Ť

âś…

Errors are shown for the “data” parameter ( or instance if it’s a modelform ), not “initial”. You need to pass the original values as the data parameter if you want to display errors.

And then just use the usual validation methods ( raising ValidationError in clean_* methods , field specific validation, etc. ). I wouldn’t mess up with the error dictionary, it’s an internal API.

👤vincent

0đź‘Ť

If you want to do custom form validation, you can implement the clean_<fieldname>() or clean() method on your form, and raise a ValidationError for each error. See the official documentation for details

👤sk1p

Leave a comment