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() {
|
$(document).ready(function() {
|
||||||
|
|
||||||
// Prevent duplicate validation messages. When the validation error is displayed inline
|
hideDuplicateValidationFieldErrors();
|
||||||
// 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){
|
});
|
||||||
|
|
||||||
|
// 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');
|
var fname = $(this).attr('name');
|
||||||
if (fname === undefined) {
|
if (fname === undefined) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var vnode = $(this).parent().find('div.invalid-feedback');
|
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');
|
var formField = $(vnode).attr('data-field');
|
||||||
$(document).find('div.validation-error').find('li').each(function(){
|
$(document).find('div.validation-error').find('li').each(function(){
|
||||||
if ($(this).attr('data-form-field') == formField) {
|
if ($(this).attr('data-form-field') == formField) {
|
||||||
if ($(vnode).is(":visible")) {
|
if ($(vnode).is(":visible") || $(vnode).css('display') === 'none') {
|
||||||
$(this).hide();
|
$(this).hide();
|
||||||
} else {
|
} else {
|
||||||
console.log('form validation feedback for '+fname+' is not visable, display main.');
|
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">
|
<div class="text-center">
|
||||||
<h1 class="h4 text-gray-900 mb-4">Create an Account!</h1>
|
<h1 class="h4 text-gray-900 mb-4">Create an Account!</h1>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{ template "top-error" . }}
|
{{ template "top-error" . }}
|
||||||
|
{{ template "validation-error" . }}
|
||||||
|
|
||||||
<form class="user" method="post" novalidate>
|
<form class="user" method="post" novalidate>
|
||||||
<div class="form-group row">
|
<div class="form-group row">
|
||||||
<div class="col-sm-6 mb-3 mb-sm-0">
|
<div class="col-sm-6 mb-3 mb-sm-0">
|
||||||
@@ -52,7 +55,7 @@
|
|||||||
<div id="divAccountZipcode"></div>
|
<div id="divAccountZipcode"></div>
|
||||||
{{template "invalid-feedback" dict "validationDefaults" $.validationDefaults "validationErrors" $.validationErrors "fieldName" "Account.Zipcode" }}
|
{{template "invalid-feedback" dict "validationDefaults" $.validationDefaults "validationErrors" $.validationErrors "fieldName" "Account.Zipcode" }}
|
||||||
</div>
|
</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>
|
<div id="divAccountRegion"></div>
|
||||||
{{template "invalid-feedback" dict "validationDefaults" $.validationDefaults "validationErrors" $.validationErrors "fieldName" "Account.Region" }}
|
{{template "invalid-feedback" dict "validationDefaults" $.validationDefaults "validationErrors" $.validationErrors "fieldName" "Account.Region" }}
|
||||||
</div>
|
</div>
|
||||||
@@ -210,6 +213,9 @@
|
|||||||
|
|
||||||
}
|
}
|
||||||
}).change();
|
}).change();
|
||||||
|
|
||||||
|
hideDuplicateValidationFieldErrors();
|
||||||
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
@@ -20,6 +20,10 @@
|
|||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
<h1 class="h4 text-gray-900 mb-4">Welcome Back!</h1>
|
<h1 class="h4 text-gray-900 mb-4">Welcome Back!</h1>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{{ template "top-error" . }}
|
||||||
|
{{ template "validation-error" . }}
|
||||||
|
|
||||||
<form class="user" method="post" novalidate>
|
<form class="user" method="post" novalidate>
|
||||||
<div class="form-group">
|
<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...">
|
<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>
|
<p class="mb-4">.....</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{{ template "top-error" . }}
|
||||||
{{ template "validation-error" . }}
|
{{ template "validation-error" . }}
|
||||||
|
|
||||||
<form class="user" method="post" novalidate>
|
<form class="user" method="post" novalidate>
|
||||||
|
@@ -21,6 +21,10 @@
|
|||||||
<h1 class="h4 text-gray-900 mb-2">Forgot Your Password?</h1>
|
<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>
|
<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>
|
</div>
|
||||||
|
|
||||||
|
{{ template "top-error" . }}
|
||||||
|
{{ template "validation-error" . }}
|
||||||
|
|
||||||
<form class="user" method="post" novalidate>
|
<form class="user" method="post" novalidate>
|
||||||
<div class="form-group">
|
<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...">
|
<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>
|
</html>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{ define "invalid-feedback" }}
|
{{ 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 }}
|
{{ if ValidationErrorHasField .validationErrors .fieldName }}
|
||||||
{{ range $verr := (ValidationFieldErrors .validationErrors .fieldName) }}{{ $verr.Display }}<br/>{{ end }}
|
{{ range $verr := (ValidationFieldErrors .validationErrors .fieldName) }}{{ $verr.Display }}<br/>{{ end }}
|
||||||
{{ else }}
|
{{ else }}
|
||||||
|
@@ -21,13 +21,12 @@
|
|||||||
{{ template "partials/topbar" . }}
|
{{ template "partials/topbar" . }}
|
||||||
<!-- End of Topbar -->
|
<!-- End of Topbar -->
|
||||||
|
|
||||||
{{ template "top-error" . }}
|
|
||||||
|
|
||||||
<!-- ============================================================== -->
|
<!-- ============================================================== -->
|
||||||
<!-- Page Content -->
|
<!-- Page Content -->
|
||||||
<!-- ============================================================== -->
|
<!-- ============================================================== -->
|
||||||
<div class="container-fluid" id="page-content">
|
<div class="container-fluid" id="page-content">
|
||||||
|
|
||||||
|
{{ template "top-error" . }}
|
||||||
{{ template "validation-error" . }}
|
{{ template "validation-error" . }}
|
||||||
|
|
||||||
{{ template "content" . }}
|
{{ template "content" . }}
|
||||||
|
@@ -154,7 +154,17 @@ func newValidator() *validator.Validate {
|
|||||||
if fl.Field().String() == "invalid" {
|
if fl.Field().String() == "invalid" {
|
||||||
return false
|
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)
|
v.RegisterValidationCtx("unique", fctx)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user