diff --git a/Bootstrap.Admin/Content/js/Longbow.Common.js b/Bootstrap.Admin/Content/js/Longbow.Common.js index e7b88bc4..1b18abc7 100644 --- a/Bootstrap.Admin/Content/js/Longbow.Common.js +++ b/Bootstrap.Admin/Content/js/Longbow.Common.js @@ -129,12 +129,13 @@ }); that.animate({ marginTop: "+=" + getHeight() }); }, - autoValidate: function (options) { + autoValidate: function (options, handler) { // validate - $(this).validate({ + var $this = $(this); + $this.validate({ validClass: "has-success", errorClass: "has-error", - ignore: "ignore", + ignore: ".ignore", rules: $.extend({}, options), highlight: function (element, errorClass, validClass) { $(element).parents('.form-group').addClass(errorClass).removeClass(validClass); @@ -156,6 +157,13 @@ $(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) { var settings = $.extend({ diff --git a/Bootstrap.Admin/Scripts/Infos.js b/Bootstrap.Admin/Scripts/Infos.js index ccd6ece8..f0e1f1fd 100644 --- a/Bootstrap.Admin/Scripts/Infos.js +++ b/Bootstrap.Admin/Scripts/Infos.js @@ -19,6 +19,32 @@ 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({ url: '../api/Infos', bootstrapTable: null, @@ -34,18 +60,22 @@ assign: [{ id: 'btnSavePassword', click: function (row, data) { - data.UserStatus = 2; - User.changePassword(data); + if ($(this).attr('data-valid') == "true") { + data.UserStatus = 2; + User.changePassword(data); + } } }, { id: 'btnSaveDisplayName', click: function (row, data) { - data.UserStatus = 1; - User.saveUserDisplayName(data, function (result) { - if (result) { - $('#userDisplayName').text(data.DisplayName); - } - }); + if ($(this).attr('data-valid') == "true") { + data.UserStatus = 1; + User.saveUserDisplayName(data, function (result) { + if (result) { + $('#userDisplayName').text(data.DisplayName); + } + }); + } } }] } diff --git a/Bootstrap.Admin/Views/Admin/Infos.cshtml b/Bootstrap.Admin/Views/Admin/Infos.cshtml index b91902e7..b830f3a4 100644 --- a/Bootstrap.Admin/Views/Admin/Infos.cshtml +++ b/Bootstrap.Admin/Views/Admin/Infos.cshtml @@ -8,6 +8,8 @@ + + } @section css { @@ -28,7 +30,7 @@