Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions declarative/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
18 changes: 18 additions & 0 deletions validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}