Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

brendensoares
Copy link
Member

See #369

validation.go Outdated
if key == "" {
keyFormatted = "Field"
} else {
var keyWords []string
Copy link
Contributor

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I sure will.

@brendensoares
Copy link
Member Author

@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 == "" {
Copy link
Contributor

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"
}

...

Copy link
Member Author

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?

Copy link
Contributor

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

Copy link
Member Author

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.

@robfig
Copy link
Contributor

robfig commented Dec 7, 2013

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!

@brendensoares
Copy link
Member Author

I'm sure we can have both, but maybe that's something to improve for Revel 2.0

@verdverm
Copy link
Contributor

@brendensoares are we fore going this for now?

@brendensoares brendensoares added this to the Backlog milestone Feb 25, 2014
@brendensoares
Copy link
Member Author

Ya, for now. I just backlogged it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status-wrong-branch type-enhancement New enhancement of existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants