flask-mongoengine icon indicating copy to clipboard operation
flask-mongoengine copied to clipboard

Password field support and automatic submit button in forms

Open jontxu opened this issue 12 years ago • 4 comments

I'm using the form generator to avoid creating forms and having redundant code.

I've got two suggestions that could be useful:

  1. When using jinja2 and WTForms {{ form.submit }} works when the class is declared in the usual way with a SubmitField. 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.
  2. PasswordField for variable names such as password or pass would 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.

jontxu avatar Oct 18 '13 22:10 jontxu

Happy to take pull requests - and if you are interested I'm looking for maintainers of this project

rozza avatar Oct 22 '13 08:10 rozza

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.

wojcikstefan avatar Nov 27 '16 05:11 wojcikstefan

+1

pierrz avatar May 28 '18 00:05 pierrz

+1

amovfx avatar Aug 23 '21 19:08 amovfx