You've already forked golang-saas-starter-kit
mirror of
https://github.com/raseels-repos/golang-saas-starter-kit.git
synced 2025-08-08 22:36:41 +02:00
Fixed validation errors
This commit is contained in:
@@ -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() {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
}
|
@@ -15,7 +15,10 @@
|
||||
<div class="text-center">
|
||||
<h1 class="h4 text-gray-900 mb-4">Create an Account!</h1>
|
||||
</div>
|
||||
|
||||
{{ template "top-error" . }}
|
||||
{{ template "validation-error" . }}
|
||||
|
||||
<form class="user" method="post" novalidate>
|
||||
<div class="form-group row">
|
||||
<div class="col-sm-6 mb-3 mb-sm-0">
|
||||
@@ -52,7 +55,7 @@
|
||||
<div id="divAccountZipcode"></div>
|
||||
{{template "invalid-feedback" dict "validationDefaults" $.validationDefaults "validationErrors" $.validationErrors "fieldName" "Account.Zipcode" }}
|
||||
</div>
|
||||
<div class="col-sm-6 mb-3 mb-sm-0" id="divAccountRegion">
|
||||
<div class="col-sm-6 mb-3 mb-sm-0">
|
||||
<div id="divAccountRegion"></div>
|
||||
{{template "invalid-feedback" dict "validationDefaults" $.validationDefaults "validationErrors" $.validationErrors "fieldName" "Account.Region" }}
|
||||
</div>
|
||||
@@ -210,6 +213,9 @@
|
||||
|
||||
}
|
||||
}).change();
|
||||
|
||||
hideDuplicateValidationFieldErrors();
|
||||
|
||||
});
|
||||
</script>
|
||||
{{end}}
|
||||
|
@@ -20,6 +20,10 @@
|
||||
<div class="text-center">
|
||||
<h1 class="h4 text-gray-900 mb-4">Welcome Back!</h1>
|
||||
</div>
|
||||
|
||||
{{ template "top-error" . }}
|
||||
{{ template "validation-error" . }}
|
||||
|
||||
<form class="user" method="post" novalidate>
|
||||
<div class="form-group">
|
||||
<input type="email" class="form-control form-control-user {{ ValidationFieldClass $.validationErrors "AuthenticateRequest.Email" }}" name="Email" value="{{ $.form.Email }}" placeholder="Enter Email Address...">
|
||||
|
@@ -22,6 +22,7 @@
|
||||
<p class="mb-4">.....</p>
|
||||
</div>
|
||||
|
||||
{{ template "top-error" . }}
|
||||
{{ template "validation-error" . }}
|
||||
|
||||
<form class="user" method="post" novalidate>
|
||||
|
@@ -21,6 +21,10 @@
|
||||
<h1 class="h4 text-gray-900 mb-2">Forgot Your Password?</h1>
|
||||
<p class="mb-4">We get it, stuff happens. Just enter your email address below and we'll send you a link to reset your password!</p>
|
||||
</div>
|
||||
|
||||
{{ template "top-error" . }}
|
||||
{{ template "validation-error" . }}
|
||||
|
||||
<form class="user" method="post" novalidate>
|
||||
<div class="form-group">
|
||||
<input type="email" class="form-control form-control-user {{ ValidationFieldClass $.validationErrors "Email" }}" name="Email" value="{{ $.form.Email }}" placeholder="Enter Email Address...">
|
||||
|
@@ -99,7 +99,7 @@
|
||||
</html>
|
||||
{{end}}
|
||||
{{ define "invalid-feedback" }}
|
||||
<div class="invalid-feedback" data-field="{{ .fieldName }}">
|
||||
<div class="invalid-feedback" style="{{ if ValidationErrorHasField .validationErrors .fieldName }}display: block;{{ end }}" data-field="{{ .fieldName }}">
|
||||
{{ if ValidationErrorHasField .validationErrors .fieldName }}
|
||||
{{ range $verr := (ValidationFieldErrors .validationErrors .fieldName) }}{{ $verr.Display }}<br/>{{ end }}
|
||||
{{ else }}
|
||||
|
@@ -21,13 +21,12 @@
|
||||
{{ template "partials/topbar" . }}
|
||||
<!-- End of Topbar -->
|
||||
|
||||
{{ template "top-error" . }}
|
||||
|
||||
<!-- ============================================================== -->
|
||||
<!-- Page Content -->
|
||||
<!-- ============================================================== -->
|
||||
<div class="container-fluid" id="page-content">
|
||||
|
||||
{{ template "top-error" . }}
|
||||
{{ template "validation-error" . }}
|
||||
|
||||
{{ template "content" . }}
|
||||
|
@@ -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)
|
||||
|
||||
|
Reference in New Issue
Block a user