From e68eb7a3da8b60b6af1bff0cce74b22fdae26095 Mon Sep 17 00:00:00 2001 From: "Jose M. Guisado" Date: Tue, 16 Feb 2021 13:30:28 +0000 Subject: 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 --- ogcp/forms/action_forms.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ogcp/forms/action_forms.py b/ogcp/forms/action_forms.py index d85b15d..a73b4d1 100644 --- a/ogcp/forms/action_forms.py +++ b/ogcp/forms/action_forms.py @@ -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')) -- cgit v1.2.3-18-g5258