1
votes

I want to create a SelectField that offers suggestions but still allow the user to enter something else.

class MyForm(Form):
    username = wtf.StringField()
    title = wtf.SelectField('Job title', choices=['Owner', 'Manager'], validate_choices=False)

WTF documentation suggests that setting validate_choices to False allows this:

Note the validate_choice parameter - by setting this to False we are telling the SelectField to skip the choice validation step and instead to accept any inputted choice without checking to see if it was one of the given choices.

But, no data entry or modification is possible with above. Is this possible or do I need another 'manual entry' field? Or, is there perhaps a way to show my suggestions in a StringField using JS similar to the way the browsers offer autocomplete suggestions for addresses etc?

1

1 Answers

0
votes

I'm not aware of any way to do this. It seems you and I are in a similar position. However, I did have an idea I wanted to share that could work for you.

Many forms will have a dropdown with a value "Other" and if you select "Other" there is another empty box that appears for you to type in. You could implement this pretty easily in wtforms. Alternatively you could have the extra box always display and just do a check that they did indeed select "Other" if they have a custom input.