Password field support and automatic submit button in forms
I'm using the form generator to avoid creating forms and having redundant code.
I've got two suggestions that could be useful:
- When using jinja2 and WTForms
{{ form.submit }}works when the class is declared in the usual way with aSubmitField. I think the point of a form is to do a POST or PUT request but adding HTML manually to a template seems pretty lame. I think adding it would be much better. - PasswordField for variable names such as
passwordorpasswould be useful to say the least. For example:
#Declaration in model
class User(Document):
#other fields
password = StringField(required=True, max_length=50)
#other fields
#Form
class UserForm():
#other fields
password = PasswordField("Password", [validators.Required()])
#other fields
submit = SubmitField("Send")
It's lackluster comparing it to the original WTForms package... they're key points, at least for me.
Happy to take pull requests - and if you are interested I'm looking for maintainers of this project
I agree that automatically adding a SubmitField could be nice. Otherwise in most situations you have to add it yourself manually in a template. What you could do right now is override flask_mongoengine.wtf.models.ModelForm, add a SubmitField to the overridden class and then call model_form(User, base_class=OverriddenModelClass).
WRT your 2nd point, you can easily change the field to PasswordField by calling model_form(User, field_args={'password': {'password': True}}). See field_args under http://docs.mongoengine.org/projects/flask-mongoengine/en/latest/#mongoengine-and-wtforms for more details.
@lafrech can you think of a reason (other than introducing a breaking change) why we shouldn't automatically add a SubmitField to every form generated with model_form? Basically it would automatically include an <input type="submit"> when rendering the form. One tricky thing about it though is that we'd probably need an extra argument passed into model_form (maybe via field_args) to define the value of the submit button, e.g. "save", "send", "confirm", etc.
+1
+1