Skip to content
This repository has been archived by the owner on Jan 14, 2022. It is now read-only.

Commit

Permalink
Merge pull request #40 from jchannon/customerrormessage
Browse files Browse the repository at this point in the history
added ErrorMessage to Field
  • Loading branch information
mholt committed Nov 9, 2015
2 parents 81bd158 + e46d508 commit 2cf3653
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,12 @@ func Validate(req *http.Request, userStruct FieldMapper) Errors {
}

addRequiredError := func() {
errs.Add([]string{fieldName}, RequiredError, "Required")
errorMsg := "Please enter a value for " + fieldName
if len(fieldSpec.ErrorMessage) > 0 {
errorMsg = fieldSpec.ErrorMessage
}

errs.Add([]string{fieldName}, RequiredError, errorMsg)
}
if fieldSpec.Required {
switch t := fieldPointer.(type) {
Expand Down Expand Up @@ -710,6 +715,9 @@ type (
// by executing this function. Useful when the custom type doesn't
// implement the Binder interface.
Binder func(string, []string, Errors) Errors

//A custom error message
ErrorMessage string
}

// Binder is an interface which can deserialize itself from a slice of string
Expand Down

0 comments on commit 2cf3653

Please sign in to comment.