-
Notifications
You must be signed in to change notification settings - Fork 10
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
Can't use FormField due to required request in __init__ #8
Comments
Thanks for creating an issue. Can you write an example code block that shows the problem you're describing? |
Do you need the full working code? I'm extracting this out of something I'm writing. |
Thanks! That helps. I have to think some more about the consequences of allowing from starlette_wtf import StarletteForm
from wtforms import Form, TextField, FormField
class AddressForm(Form):
street_addr = TextField(
"Street Address",
validators=[],
)
city = TextField(
"City",
validators=[],
)
state = TextField("State", validators=[Length(min=2, max=2)])
zipcode = TextField("Zipcode", validators=[Length(min=5, max=5)])
class CreateSchoolForm(StarletteForm):
name = TextField(
"School Name",
validators=[DataRequired("Please provide a school name")],
)
address = FormField(AddressForm) |
StarletteForm classes can't be used in FormField. This is becuase the initializer requires a Request operator. The request should be optional in the initializer and maybe pasted in with the validate_on_submit. Possible there needs to be a StarletteFormField class that passes its request object to the form passed in to it? But I think the best route would be to have an init that doesn't require positional arguments just like WTForms' Form class and then just use a load_form_data(request) member function to populate data. To be backwards compatible, probably keeping the request object as optional in the init function would be smart.
The text was updated successfully, but these errors were encountered: