문제

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