mirror of
https://github.com/haiwen/seahub.git
synced 2025-04-28 03:10:45 +00:00
[new-repo]added input valid in fe
This commit is contained in:
parent
542a8e8256
commit
e241233a8d
2
forms.py
2
forms.py
@ -97,7 +97,7 @@ class RepoCreateForm(forms.Form):
|
||||
passwd = self.cleaned_data['passwd']
|
||||
passwd_again = self.cleaned_data['passwd_again']
|
||||
if passwd != passwd_again:
|
||||
raise forms.ValidationError(_("The two password fields didn't match."))
|
||||
raise forms.ValidationError(_("Passwords don't match"))
|
||||
return self.cleaned_data
|
||||
|
||||
class SharedRepoCreateForm(RepoCreateForm):
|
||||
|
@ -1,3 +1,4 @@
|
||||
{% load i18n %}
|
||||
//repo-create-form
|
||||
$('#repo-create')
|
||||
.click(function() {
|
||||
@ -18,17 +19,48 @@ $('#encrypt-switch').click(function () {
|
||||
$('#repo-create-form input[type="password"]').attr('disabled', true).addClass('input-disabled');
|
||||
}
|
||||
});
|
||||
$('#repo-create-submit').click(function() {
|
||||
var passwd = $('#repo-create-form input[name="passwd"]'),
|
||||
passwd_again = $('#repo-create-form input[name="passwd_again"]');
|
||||
var self = $(this);
|
||||
self.attr('disabled', 'disabled');
|
||||
$('#repo-create-form').submit(function() {
|
||||
var passwd = $(this).find('input[name="passwd"]'),
|
||||
passwd_again = $(this).find('input[name="passwd_again"]');
|
||||
|
||||
var form = 'repo-create-form';
|
||||
if (!$.trim($('#repo-name').val())) {
|
||||
apply_form_error(form, "{% trans "Name can't be empty" %}");
|
||||
return false;
|
||||
}
|
||||
if (!$.trim($('#repo-desc').val())) {
|
||||
apply_form_error(form, "{% trans "Description can't be empty" %}");
|
||||
return false;
|
||||
}
|
||||
if ($('#encrypt-switch').attr('checked')) {
|
||||
if (!$.trim(passwd.val())) {
|
||||
apply_form_error(form, "{% trans "Please enter password" %}");
|
||||
return false;
|
||||
}
|
||||
if ($.trim(passwd.val()).length < 3) {
|
||||
apply_form_error(form, "{% trans "Password is too short (minimum is 3 characters)" %}");
|
||||
return false;
|
||||
}
|
||||
if ($.trim(passwd.val()).length > 15) {
|
||||
apply_form_error(form, "{% trans "Password is too long (maximum is 15 characters)" %}");
|
||||
return false;
|
||||
}
|
||||
if (!$.trim(passwd_again.val())) {
|
||||
apply_form_error(form, "{% trans "Please enter the password again" %}");
|
||||
return false;
|
||||
}
|
||||
if ($.trim(passwd.val()) != $.trim(passwd_again.val())) {
|
||||
apply_form_error(form, "{% trans "Passwords don't match" %}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
var submit_btn = $(this).find('input[type="submit"]');
|
||||
disable(submit_btn);
|
||||
$.ajax({
|
||||
url: '{{ post_url }}',
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
cache: 'false',
|
||||
beforeSend: prepareCSRFToken,
|
||||
data: {
|
||||
'repo_name': $('#repo-name').val(),
|
||||
@ -45,7 +77,7 @@ $('#repo-create-submit').click(function() {
|
||||
location.reload(true);
|
||||
} else {
|
||||
apply_form_error('repo-create-form', data['error']);
|
||||
self.removeAttr('disabled');
|
||||
enable(submit_btn);
|
||||
}
|
||||
},
|
||||
error: function(data, textStatus, jqXHR) {
|
||||
@ -53,7 +85,7 @@ $('#repo-create-submit').click(function() {
|
||||
$.each(errors, function(index, value) {
|
||||
apply_form_error('repo-create-form', value[0]);
|
||||
});
|
||||
self.removeAttr('disabled');
|
||||
enable(submit_btn);
|
||||
}
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user