New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/descriptive validation messages #371
base: master
Are you sure you want to change the base?
Feature/descriptive validation messages #371
Conversation
validation.go
Outdated
if key == "" { | ||
keyFormatted = "Field" | ||
} else { | ||
var keyWords []string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like you are using this as a slice of characters rather than slice of strings. A better type for that would be []rune
Also, this sort of routine is easy to extract into a function and unit testing -- do you mind writing a test for it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I sure will.
…t for field formatting function
@robfig can you accept this PR? |
@@ -243,6 +244,24 @@ func restoreValidationErrors(req *http.Request) ([]*ValidationError, error) { | |||
return errors, err | |||
} | |||
|
|||
// Format field name for display | |||
func formatFieldName(field string) (formattedField string) { | |||
if field == "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's more idiomatic to do checks and return early rather than nesting large blocks of code.
For example
if field == "" {
return "Field"
}
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see what you're saying, but what are you basing your measure of what's idiomatic for Go?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What everyone on the golang-nuts mailing list says.
It's not the easiest thing to search for, but here's one reference:
http://talks.golang.org/2013/bestpractices.slide
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, I'll get my code in line with the current best practices sometime this week, unless you'd rather scrap this PR for now in favor of reworking the validation system.
LG, just 1 comment. It would be nice if it was more flexible in general -- the previous messages were optimized for showing the error message inline next to the field (probably the UX-preferred way to handle form validation). These defaults are optimized for showing all messages at the top (Eng-preferred way). Too bad we can't have both! |
I'm sure we can have both, but maybe that's something to improve for Revel 2.0 |
@brendensoares are we fore going this for now? |
Ya, for now. I just backlogged it. |
See #369