I know using form_extra_fields can add an extra field in flask-admin. But how can I make it 'required'? Thanks in advance.
form_extra_fields = {
'password2': PasswordField('Password')
}
The basic concept behind Flask-Admin, is that it lets you build complicated interfaces by grouping individual views together in classes: Each web page you see on the frontend, represents a method on a class that has explicitly been added to the interface.
Thanks a lot, Mech. Actually I figured out a simpler way:
from wtforms import validators
form_extra_fields = {
'password2': PasswordField('password',[validators.DataRequired()])
}
You can use WTForms. See example below, pulled from Flask's documentation:
from wtforms import Form, BooleanField, TextField, PasswordField, validators
class RegistrationForm(Form):
username = TextField('Username', [validators.Length(min=4, max=25)])
email = TextField('Email Address', [validators.Length(min=6, max=35)])
password = PasswordField('New Password', [
validators.Required(),
validators.EqualTo('confirm', message='Passwords must match')
])
confirm = PasswordField('Repeat Password')
accept_tos = BooleanField('I accept the TOS', [validators.Required()])
See the link for the other snippets (view, template, etc).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With