質問

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