修改BUG:个人中心保存显示名称与更改密码没有客户端验证

This commit is contained in:
Argo-Lenovo 2016-11-17 14:50:19 +08:00
parent 1b9d44d68a
commit 9f1d4650f6
3 changed files with 55 additions and 15 deletions

View File

@ -129,12 +129,13 @@
}); });
that.animate({ marginTop: "+=" + getHeight() }); that.animate({ marginTop: "+=" + getHeight() });
}, },
autoValidate: function (options) { autoValidate: function (options, handler) {
// validate // validate
$(this).validate({ var $this = $(this);
$this.validate({
validClass: "has-success", validClass: "has-success",
errorClass: "has-error", errorClass: "has-error",
ignore: "ignore", ignore: ".ignore",
rules: $.extend({}, options), rules: $.extend({}, options),
highlight: function (element, errorClass, validClass) { highlight: function (element, errorClass, validClass) {
$(element).parents('.form-group').addClass(errorClass).removeClass(validClass); $(element).parents('.form-group').addClass(errorClass).removeClass(validClass);
@ -156,6 +157,13 @@
$(element).popover('show'); $(element).popover('show');
} }
}); });
if ($.isArray(handler.button)) {
$.each(handler.button, function (index, btn) {
$('#' + btn).on('click', function () {
$(this).attr('data-valid', $this.valid());
});
});
}
}, },
smartTable: function (options) { smartTable: function (options) {
var settings = $.extend({ var settings = $.extend({

View File

@ -19,6 +19,32 @@
if (!!url) $headerIcon.attr('src', url); if (!!url) $headerIcon.attr('src', url);
}); });
$('#infoDataForm').autoValidate({
displayName: {
required: true,
maxlength: 50
}
}, {
button: ['btnSaveDisplayName']
});
$('#passwordDataForm').autoValidate({
currentPassword: {
required: true,
maxlength: 50
},
newPassword: {
required: true,
maxlength: 50
},
confirmPassword: {
required: true,
equalTo: "#newPassword",
maxlength: 50
}
}, {
button: ['btnSavePassword']
});
var bsa = new BootstrapAdmin({ var bsa = new BootstrapAdmin({
url: '../api/Infos', url: '../api/Infos',
bootstrapTable: null, bootstrapTable: null,
@ -34,18 +60,22 @@
assign: [{ assign: [{
id: 'btnSavePassword', id: 'btnSavePassword',
click: function (row, data) { click: function (row, data) {
data.UserStatus = 2; if ($(this).attr('data-valid') == "true") {
User.changePassword(data); data.UserStatus = 2;
User.changePassword(data);
}
} }
}, { }, {
id: 'btnSaveDisplayName', id: 'btnSaveDisplayName',
click: function (row, data) { click: function (row, data) {
data.UserStatus = 1; if ($(this).attr('data-valid') == "true") {
User.saveUserDisplayName(data, function (result) { data.UserStatus = 1;
if (result) { User.saveUserDisplayName(data, function (result) {
$('#userDisplayName').text(data.DisplayName); if (result) {
} $('#userDisplayName').text(data.DisplayName);
}); }
});
}
} }
}] }]
} }

View File

@ -8,6 +8,8 @@
<script src="~/content/js/sweetalert.js"></script> <script src="~/content/js/sweetalert.js"></script>
<script src="~/Content/js/fileinput.js"></script> <script src="~/Content/js/fileinput.js"></script>
<script src="~/Content/js/fileinput.zh.js"></script> <script src="~/Content/js/fileinput.zh.js"></script>
<script src="~/Content/js/jquery.validate.js"></script>
<script src="~/Content/js/messages_zh.js"></script>
<script src="~/scripts/Infos.js"></script> <script src="~/scripts/Infos.js"></script>
} }
@section css { @section css {
@ -28,7 +30,7 @@
<div class="row"> <div class="row">
<div class="form-group col-xs-12 col-sm-6"> <div class="form-group col-xs-12 col-sm-6">
<label class="control-label" for="userName">登陆名称</label> <label class="control-label" for="userName">登陆名称</label>
<input type="text" class="form-control" id="userName" name="userName" value="@Model.UserName" readonly /> <input type="text" class="form-control ignore" id="userName" name="userName" value="@Model.UserName" readonly />
</div> </div>
<div class="form-group col-xs-12 col-sm-6"> <div class="form-group col-xs-12 col-sm-6">
<label class="control-label" for="DisplayName">显示名称</label> <label class="control-label" for="DisplayName">显示名称</label>
@ -46,15 +48,15 @@
<div class="panel-body"> <div class="panel-body">
<form id="passwordDataForm" name="passwordDataForm" class="form-inline" role="form"> <form id="passwordDataForm" name="passwordDataForm" class="form-inline" role="form">
<div class="row"> <div class="row">
<div class="form-group col-xs-12"> <div class="form-group col-lg4 col-md-4 col-sm-12 col-xs-12">
<label class="control-label" for="currentPassword">当前密码: </label> <label class="control-label" for="currentPassword">当前密码: </label>
<input type="password" class="form-control" id="currentPassword" name="currentPassword" placeholder="登陆密码" maxlength="50" /> <input type="password" class="form-control" id="currentPassword" name="currentPassword" placeholder="登陆密码" maxlength="50" />
</div> </div>
<div class="form-group col-xs-6"> <div class="form-group col-lg-4 col-md-4 col-sm-6 col-xs-12">
<label class="control-label" for="newPassword">最新密码: </label> <label class="control-label" for="newPassword">最新密码: </label>
<input type="password" class="form-control" id="newPassword" name="newPassword" placeholder="新密码" maxlength="50" /> <input type="password" class="form-control" id="newPassword" name="newPassword" placeholder="新密码" maxlength="50" />
</div> </div>
<div class="form-group col-xs-6"> <div class="form-group col-lg-4 col-md-4 col-sm-6 col-xs-12">
<label class="control-label" for="confirmPassword">确认密码: </label> <label class="control-label" for="confirmPassword">确认密码: </label>
<input type="password" class="form-control" id="confirmPassword" name="confirmPassword" placeholder="与新密码一致" maxlength="50" /> <input type="password" class="form-control" id="confirmPassword" name="confirmPassword" placeholder="与新密码一致" maxlength="50" />
</div> </div>