diff --git a/cmd/web-app/static/assets/js/custom.js b/cmd/web-app/static/assets/js/custom.js index 869a01a..f8e91d2 100644 --- a/cmd/web-app/static/assets/js/custom.js +++ b/cmd/web-app/static/assets/js/custom.js @@ -1,19 +1,28 @@ $(document).ready(function() { - // Prevent duplicate validation messages. When the validation error is displayed inline - // when the form value, don't display the form error message at the top of the page. - $(this).find('#page-content form').find('input, select, textarea').each(function(index){ + hideDuplicateValidationFieldErrors(); + +}); + +// Prevent duplicate validation messages. When the validation error is displayed inline +// when the form value, don't display the form error message at the top of the page. +function hideDuplicateValidationFieldErrors() { + $(document).find('#page-content form').find('input, select, textarea').each(function(index){ var fname = $(this).attr('name'); if (fname === undefined) { return; } var vnode = $(this).parent().find('div.invalid-feedback'); + if (vnode.length == 0) { + vnode = $(this).parent().parent().find('div.invalid-feedback'); + } + var formField = $(vnode).attr('data-field'); $(document).find('div.validation-error').find('li').each(function(){ if ($(this).attr('data-form-field') == formField) { - if ($(vnode).is(":visible")) { + if ($(vnode).is(":visible") || $(vnode).css('display') === 'none') { $(this).hide(); } else { console.log('form validation feedback for '+fname+' is not visable, display main.'); @@ -21,5 +30,4 @@ $(document).ready(function() { } }); }); - -}); +} \ No newline at end of file diff --git a/cmd/web-app/templates/content/signup-step1.gohtml b/cmd/web-app/templates/content/signup-step1.gohtml index 95669a0..57b5c86 100644 --- a/cmd/web-app/templates/content/signup-step1.gohtml +++ b/cmd/web-app/templates/content/signup-step1.gohtml @@ -15,7 +15,10 @@

Create an Account!

+ {{ template "top-error" . }} + {{ template "validation-error" . }} +
@@ -52,7 +55,7 @@
{{template "invalid-feedback" dict "validationDefaults" $.validationDefaults "validationErrors" $.validationErrors "fieldName" "Account.Zipcode" }}
-
+
{{template "invalid-feedback" dict "validationDefaults" $.validationDefaults "validationErrors" $.validationErrors "fieldName" "Account.Region" }}
@@ -210,6 +213,9 @@ } }).change(); + + hideDuplicateValidationFieldErrors(); + }); {{end}} diff --git a/cmd/web-app/templates/content/user-login.gohtml b/cmd/web-app/templates/content/user-login.gohtml index 845ef7c..fc1bf15 100644 --- a/cmd/web-app/templates/content/user-login.gohtml +++ b/cmd/web-app/templates/content/user-login.gohtml @@ -20,6 +20,10 @@

Welcome Back!

+ + {{ template "top-error" . }} + {{ template "validation-error" . }} +
diff --git a/cmd/web-app/templates/content/user-reset-confirm.gohtml b/cmd/web-app/templates/content/user-reset-confirm.gohtml index 3ec7dbe..ef468fe 100644 --- a/cmd/web-app/templates/content/user-reset-confirm.gohtml +++ b/cmd/web-app/templates/content/user-reset-confirm.gohtml @@ -22,6 +22,7 @@

.....

+ {{ template "top-error" . }} {{ template "validation-error" . }} diff --git a/cmd/web-app/templates/content/user-reset-password.gohtml b/cmd/web-app/templates/content/user-reset-password.gohtml index 6e4e72b..f74aae4 100644 --- a/cmd/web-app/templates/content/user-reset-password.gohtml +++ b/cmd/web-app/templates/content/user-reset-password.gohtml @@ -21,6 +21,10 @@

Forgot Your Password?

We get it, stuff happens. Just enter your email address below and we'll send you a link to reset your password!

+ + {{ template "top-error" . }} + {{ template "validation-error" . }} +
diff --git a/cmd/web-app/templates/layouts/base.gohtml b/cmd/web-app/templates/layouts/base.gohtml index 49b6c55..63c7077 100644 --- a/cmd/web-app/templates/layouts/base.gohtml +++ b/cmd/web-app/templates/layouts/base.gohtml @@ -99,7 +99,7 @@ {{end}} {{ define "invalid-feedback" }} -
+
{{ if ValidationErrorHasField .validationErrors .fieldName }} {{ range $verr := (ValidationFieldErrors .validationErrors .fieldName) }}{{ $verr.Display }}
{{ end }} {{ else }} diff --git a/cmd/web-app/templates/partials/page-wrapper.tmpl b/cmd/web-app/templates/partials/page-wrapper.tmpl index 95115f5..db427c6 100644 --- a/cmd/web-app/templates/partials/page-wrapper.tmpl +++ b/cmd/web-app/templates/partials/page-wrapper.tmpl @@ -21,13 +21,12 @@ {{ template "partials/topbar" . }} - {{ template "top-error" . }} -
+ {{ template "top-error" . }} {{ template "validation-error" . }} {{ template "content" . }} diff --git a/internal/platform/web/webcontext/transvalidate.go b/internal/platform/web/webcontext/transvalidate.go index d17cf0d..3f4b4dc 100644 --- a/internal/platform/web/webcontext/transvalidate.go +++ b/internal/platform/web/webcontext/transvalidate.go @@ -154,7 +154,17 @@ func newValidator() *validator.Validate { if fl.Field().String() == "invalid" { return false } - return ctx.Value(KeyTagUnique).(bool) + + cv := ctx.Value(KeyTagUnique) + if cv == nil { + return false + } + + if v, ok := cv.(bool); ok { + return v + } + + return false } v.RegisterValidationCtx("unique", fctx)