Add example image creation WTForms validator

Adds in a declarative way the validation of the image name form control
when creating a partition image.

This commit serves as an example of adding a predefined validator of the
WTForms module. Custom validator may be added by creating a given
function and appending it to the list of validators.

See https://wtforms.readthedocs.io/en/2.3.x/validators/#custom-validators
multi-ogserver
Jose M. Guisado 2021-02-16 13:30:28 +00:00
parent 622f0bacbc
commit e68eb7a3da
1 changed files with 3 additions and 1 deletions

View File

@ -2,6 +2,7 @@ from wtforms import (
Form, SubmitField, HiddenField, SelectField, BooleanField, IntegerField,
StringField, RadioField
)
from wtforms.validators import InputRequired
from flask_wtf import FlaskForm
from flask_babel import _
@ -78,6 +79,7 @@ class ClientDetailsForm(FlaskForm):
class ImageCreateForm(FlaskForm):
ip = HiddenField()
os = SelectField(label=_('OS'), choices=[])
name = StringField(label=_('Image name'))
name = StringField(label=_('Image name'),
validators=[InputRequired()])
description = StringField(label=_('Description'))
create = SubmitField(label=_('Create'))