diff --git a/declarative/validators.go b/declarative/validators.go index 7f6e8e66..89f2c0ab 100644 --- a/declarative/validators.go +++ b/declarative/validators.go @@ -42,6 +42,13 @@ func (SelRequired) Create() (walk.Validator, error) { return walk.SelectionRequiredValidator(), nil } +type NotEmpty struct { +} + +func (NotEmpty) Create() (walk.Validator, error) { + return walk.NotEmptyValidator(), nil +} + type dMultiValidator struct { validators []Validator } diff --git a/validators.go b/validators.go index 2f256f1c..65fc1260 100644 --- a/validators.go +++ b/validators.go @@ -150,3 +150,21 @@ func (selectionRequiredValidator) Validate(v interface{}) error { return nil } + +type notEmptyValidator struct { +} + +var notEmptyValidatorSingleton Validator = notEmptyValidator{} + +func NotEmptyValidator() Validator { + return notEmptyValidatorSingleton +} + +func (notEmptyValidator) Validate(v interface{}) error { + if s := v.(string); len(s) <= 0 { + return NewValidationError( + tr("Empty field", "walk"), + tr("Please fill out the required fields.", "walk")) + } + return nil +}