سؤال

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