Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SelectField <optgroup> support #656

Closed
azmeuk opened this issue Oct 4, 2020 · 1 comment · Fixed by #667
Closed

SelectField <optgroup> support #656

azmeuk opened this issue Oct 4, 2020 · 1 comment · Fixed by #667
Labels
enhancement New feature, or existing feature improvement newcomers An easy task to tackle

Comments

@azmeuk
Copy link
Member

azmeuk commented Oct 4, 2020

It would be nice to support optgroup with SelectField and SelectMultipleField. Here is an implementation suggestion:

>>> import wtforms
>>> class F(wtforms.Form):
...     foo = SelectField(choices={
...         "hello": [
...             ("a", "foo"),
...             ("b", "bar"),
...         ],
...         "world": [
...             ("c", "foobaz"),
...             ("d", "barbaz"),
...         ],
...     })
...
>>> F().foo()
<select id="foo" name="foo">
<optgroup label="hello">
<select value="a">foo</select>
<select value="b">bar</select>
</optgroup>
<optgroup label="world">
<select value="c">foobaz</select>
<select value="d">barbaz</select>
</optgroup>
</select>
@azmeuk azmeuk added enhancement New feature, or existing feature improvement newcomers An easy task to tackle labels Oct 4, 2020
@azmeuk azmeuk linked a pull request Nov 4, 2020 that will close this issue
@jefke-glider
Copy link

I suppose it is not possible to have a mixed SelectField, I mean some items with and other without an optgroup?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature, or existing feature improvement newcomers An easy task to tackle
Development

Successfully merging a pull request may close this issue.

2 participants