Skip to content
New issue

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

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

Already on GitHub? # to your account

Field render kwargs are not populated to the inputs of RadioField #490

Closed
dcrosta opened this issue May 27, 2019 · 0 comments · Fixed by #688
Closed

Field render kwargs are not populated to the inputs of RadioField #490

dcrosta opened this issue May 27, 2019 · 0 comments · Fixed by #688
Labels
bug Unexpected behavior

Comments

@dcrosta
Copy link

dcrosta commented May 27, 2019

In most cases you can control HTML attributes of the rendered fields via keyword arguments to the form field's __call__ method. This doesn't work right for RadioField (or probably anything that uses FieldList, where the keyword arguments are consumed by the wrapping <ul> element, and not passed on to the actual <input>s (or whatever the nested fields are):

>>> from wtforms import Form
>>> from wtforms.fields import RadioField, SelectField
>>> class MyForm(Form):
...     a_or_b = SelectField(choices=[("A", "A"), ("B", "B")])
...
>>> f = MyForm()
>>> f.a_or_b(disabled=True)
'<select disabled id="a_or_b" name="a_or_b"><option value="A">A</option><option value="B">B</option></select>'

For SelectField (for instance), the disabled attribute is applied to the <select>.

>>> class MyOtherForm(Form):
...     a_or_b = RadioField(choices=[("A", "A"), ("B", "B")])
...
>>> f = MyOtherForm()
>>> f.a_or_b(disabled=True)
'<ul disabled id="a_or_b"><li><input id="a_or_b-0" name="a_or_b" type="radio" value="A"> <label for="a_or_b-0">A</label></li><li><input id="a_or_b-1" name="a_or_b" type="radio" value="B"> <label for="a_or_b-1">B</label></li></ul>'

With RadioField, the disabled attribute is put on the <ul>.

I think this is slightly tricky to solve, since users might want this behavior in some cases (eg to style an element by passing the class_ keyword argument). I'm willing to take a stab at a solution, but I'm not sure how best to approach it, so I'm open to ideas.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Unexpected behavior
Development

Successfully merging a pull request may close this issue.

2 participants