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?

有帮助吗?

解决方案

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']]
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top