summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJose M. Guisado <jguisado@soleta.eu>2021-02-16 13:30:28 +0000
committerJose M. Guisado <jguisado@soleta.eu>2021-02-16 13:30:28 +0000
commite68eb7a3da8b60b6af1bff0cce74b22fdae26095 (patch)
tree33736dc14a4571605dce1e8c6fcf33d69cdb0a66
parent622f0bacbc5a31f1e69d652d85f8581e22ae31c9 (diff)
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
-rw-r--r--ogcp/forms/action_forms.py4
1 files changed, 3 insertions, 1 deletions
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'))