I need compatibility with some existing HTML that uses dashes in the name attribute, but I have yet to find a way to override it with wtforms. The documentation for wtforms.fields.core.Field mentions the following about _name:
The name of this field, passed by the enclosing form during its construction. You should never pass this value yourself.
This makes me think that I should be able to override the name in the enclosing form. But in that case - where? Here's a failing test that shows what I'm expecting to be able to do:
import wtforms
from werkzeug.datastructures import ImmutableMultiDict
class MyForm(wtforms.Form):
my_field_id = wtforms.IntegerField('My field', id='my-field',
_name='my-field')
my_data = ImmutableMultiDict([('my-field', '2')])
my_form = MyForm(my_data)
assert my_form.my_field_id.name == 'my-field' # Instead `my_field_id`
assert my_form.my_field_id.data == 2 # Instead `None`
Instead I have to use this custom field to get what I'm looking for:
import wtforms
class MyCustomIntegerField(wtforms.IntegerField):
def __init__(self, *args, **kwargs):
name = kwargs.pop('name', None)
super().__init__(*args, **kwargs)
if name:
self.name = name
Am I missing something here?
I need compatibility with some existing HTML that uses dashes in the
nameattribute, but I have yet to find a way to override it with wtforms. The documentation forwtforms.fields.core.Fieldmentions the following about_name:This makes me think that I should be able to override the name in the enclosing form. But in that case - where? Here's a failing test that shows what I'm expecting to be able to do:
Instead I have to use this custom field to get what I'm looking for:
Am I missing something here?