0

Need to populate the choices of the SelectField (WTF Form) using a function. I do not want to add the choices data in the SelectField itself.

class TestForm(FlaskForm):
      dropdown = SelectField(choices=[])
      
      def form_overrided_method(self):
           self.dropdown.choices = [('A', 'A')]
    

1 Answer 1

2

You can apply values to the choices in the __init__ function of your TestForm class:

class TestForm(FlaskForm):
    dropdown = SelectField('Dropdown', coerce=int)

    def __init__(self, *args, **kwargs):
        super(TestForm, self).__init__(*args, **kwargs)
        self.dropdown.choices = [(1, 'A'),...]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.