Question

Is there any way to change a form element after the form is cleaned?

There's some form logic that is affected by other fields. In certain cases I want to add an additional choice to a ChoiceField after the clean function runs if the form is invalid. Is there a way to do this?

Était-ce utile?

La solution

The user who submits an invalid form should be rewarded with additional options? Does not make sense to me... but yeah you can always change the choices available in a form field:

def clean(self):
    self.fields['some_choice_field'].choices = [[1,'one'],[2, 'two'],[None, 'I refuse to answer']]
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top