I have a form that has a set of fields. For example it could be: name, surname and email.
Form has two submit button on it: save and close. And there are two validation scenarios.
In first after ‘save’ button was clicked form checks whether field “name” has a value or not. If it has the Database will be updated.
In second scenario I click on ‘close’ button. And there should be another validation: name is not empty and contains certain value, surname is not empty and email contains some certain domain.
So how can i implement all these validation scenarios for one form. I see only bad solution like it will be some if-else statements in form clean() method.
I don’t see why it would be so bad to have if/else in the
save()method. I’d probably do something like this:I’m writing this from my head and haven’t tested it but an approach like this should be good for keeping the validation out of the view.