1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-12-22 12:54:53 -05:00

register js validation

This commit is contained in:
FuXiaoHei 2014-03-06 22:55:32 +08:00
parent 4b912b9ae6
commit 9cd14f97c2
5 changed files with 55 additions and 15 deletions

View file

@ -1,7 +1,9 @@
var Gogits = {};
var Gogits = {
"PageIsSignup": false
};
(function($){
Gogits.showTooltips = function(){
(function ($) {
Gogits.showTooltips = function () {
$("body").tooltip({
selector: "[data-toggle=tooltip]"
//container: "body"
@ -13,10 +15,48 @@ var Gogits = {};
}
$(selector).tab("show");
$(selector).find("li:eq(" + index + ") a").tab("show");
}
};
Gogits.validateForm = function (selector, options) {
var $form = $(selector);
options = options || {};
options.showErrors = function (map, list) {
var $error = $form.find('.form-error').addClass('hidden');
$('.has-error').removeClass("has-error");
$error.text(list[0].message).show().removeClass("hidden");
$(list[0].element).parents(".form-group").addClass("has-error");
};
$form.validate(options);
};
})(jQuery);
function initCore(){
function initCore() {
Gogits.showTooltips();
}
function initRegister() {
$.getScript("/js/jquery.validate.min.js", function () {
Gogits.validateForm("#gogs-login-card", {
rules: {
"username": {
required: true,
minlength: 5,
maxlength: 30
},
"email": {
required: true,
email: true
},
"passwd": {
required: true,
minlength: 6,
maxlength: 30
},
"re-passwd": {
required: true,
equalTo: "input[name=passwd]"
}
}
});
});
}

2
public/js/jquery.validate.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View file

@ -112,6 +112,7 @@ func SignIn(req *http.Request, r render.Render, session sessions.Session) {
func SignUp(form auth.RegisterForm, data base.TmplData, req *http.Request, r render.Render) {
data["Title"] = "Sign Up"
data["PageIsSignUp"] = true
if req.Method == "GET" {
r.HTML(200, "user/signup", data)

View file

@ -1,6 +1,7 @@
<script>
$(function(){
initCore();
initCore();
{{if .PageIsSignUp}}initRegister();{{end}}
});
</script>
</body>

View file

@ -3,41 +3,37 @@
<div class="container" id="gogs-body">
<form action="/user/sign_up" method="post" class="form-horizontal gogs-card" id="gogs-login-card">
<h3>Sign Up</h3>
{{if .HasError}}
<div class="alert alert-danger">{{.ErrorMsg}}</div>
{{end}}
<div class="alert alert-danger form-error{{if .HasError}}{{else}} hidden{{end}}">{{.ErrorMsg}}</div>
<div class="form-group {{if .Err_Username}}has-error has-feedback{{end}}">
<label class="col-md-4 control-label">Username: </label>
<div class="col-md-6">
<input name="username" class="form-control" placeholder="Type your username" value="{{.username}}">
<input name="username" class="form-control" placeholder="Type your username" value="{{.username}}" required="required" title="Username must contain at least has 5 characters">
</div>
</div>
<div class="form-group {{if .Err_Email}}has-error has-feedback{{end}}">
<label class="col-md-4 control-label">Email: </label>
<div class="col-md-6">
<input name="email" class="form-control" placeholder="Type your e-mail address" value="{{.email}}">
<input name="email" class="form-control" placeholder="Type your e-mail address" value="{{.email}}" required="required" title="Email is not valid">
</div>
</div>
<div class="form-group {{if .Err_Password}}has-error has-feedback{{end}}">
<label class="col-md-4 control-label">Password: </label>
<div class="col-md-6">
<input name="passwd" type="password" class="form-control" placeholder="Type your password">
<input name="passwd" type="password" class="form-control" placeholder="Type your password" required="required" title="Password must contain at least has 6 characters">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Re-type: </label>
<div class="col-md-6">
<input type="password" class="form-control" placeholder="Re-type your password">
<input name="re-passwd" type="password" class="form-control" placeholder="Re-type your password" required="required" title="Re-type Password must be same to Password">
</div>
</div>
<div class="form-group">
<div class="col-md-offset-4 col-md-6">
<button type="submit" class="btn btn-lg btn-primary">Create an account</button>
</div>
</div>
<div class="form-group">
<div class="col-md-offset-4 col-md-6">
<a href="/user/login">Already have an account? Sign in now!</a>