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
Override field's name attribute? #205
Comments
I noticed this is mentioned in #154:
Hopefully we can get it earlier though 😉 |
Just ran across this today when integrating with a third-party that requires special characters in the form submission. Primarily |
Will be supported in 3.0 as you mentioned |
@jmagnusson a workaround is to override form meta when binding a field. from wtforms.meta import DefaultMeta
class BindNameMeta(DefaultMeta):
def bind_field(self, form, unbound_field, options):
if 'custom_name' in unbound_field.kwargs:
options['name'] = unbound_field.kwargs.pop('custom_name')
return unbound_field.bind(form=form, **options) This allows you to provide a parameter class PostForm(Form):
my_title = StringField(custom_name='my-title') Just keep in mind that you have to subclass from your own import wtforms
class Form(wtforms.Form):
meta = BindNameMeta |
thanks bmwant, i just needed to change meta to Meta. import wtforms
class Form(wtforms.Form):
Meta = BindNameMeta |
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 forwtforms.fields.core.Field
mentions 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?
The text was updated successfully, but these errors were encountered: