Commit d4cf3ae3 by naan1993

部门管理增加表单验证

parent 7f1f8d6a
@layout("/common/_container.html"){ @layout("/common/_container.html"){
<div class="ibox float-e-margins"> <div class="ibox float-e-margins">
<div class="ibox-content"> <div class="ibox-content">
<div class="form-horizontal"> <div class="form-horizontal" id="deptInfoForm">
<input type="hidden" id="id" value=""> <input type="hidden" id="id" value="">
......
@layout("/common/_container.html"){ @layout("/common/_container.html"){
<div class="ibox float-e-margins"> <div class="ibox float-e-margins">
<div class="ibox-content"> <div class="ibox-content">
<div class="form-horizontal"> <div class="form-horizontal" id="deptInfoForm">
<input type="hidden" id="id" value="${dept.id}"> <input type="hidden" id="id" value="${dept.id}">
......
...@@ -3,7 +3,30 @@ ...@@ -3,7 +3,30 @@
*/ */
var DeptInfoDlg = { var DeptInfoDlg = {
deptInfoData : {}, deptInfoData : {},
zTreeInstance : null zTreeInstance : null,
validateFields: {
simplename: {
validators: {
notEmpty: {
message: '部门名称不能为空'
}
}
},
fullname: {
validators: {
notEmpty: {
message: '部门全称不能为空'
}
}
},
pName: {
validators: {
notEmpty: {
message: '上级名称不能为空'
}
}
}
}
}; };
/** /**
...@@ -86,6 +109,15 @@ DeptInfoDlg.collectData = function() { ...@@ -86,6 +109,15 @@ DeptInfoDlg.collectData = function() {
} }
/** /**
* 验证数据是否为空
*/
DeptInfoDlg.validate = function () {
$('#deptInfoForm').data("bootstrapValidator").resetForm();
$('#deptInfoForm').bootstrapValidator('validate');
return $("#deptInfoForm").data('bootstrapValidator').isValid();
}
/**
* 提交添加部门 * 提交添加部门
*/ */
DeptInfoDlg.addSubmit = function() { DeptInfoDlg.addSubmit = function() {
...@@ -93,6 +125,10 @@ DeptInfoDlg.addSubmit = function() { ...@@ -93,6 +125,10 @@ DeptInfoDlg.addSubmit = function() {
this.clearData(); this.clearData();
this.collectData(); this.collectData();
if (!this.validate()) {
return;
}
//提交信息 //提交信息
var ajax = new $ax(Feng.ctxPath + "/dept/add", function(data){ var ajax = new $ax(Feng.ctxPath + "/dept/add", function(data){
Feng.success("添加成功!"); Feng.success("添加成功!");
...@@ -113,6 +149,10 @@ DeptInfoDlg.editSubmit = function() { ...@@ -113,6 +149,10 @@ DeptInfoDlg.editSubmit = function() {
this.clearData(); this.clearData();
this.collectData(); this.collectData();
if (!this.validate()) {
return;
}
//提交信息 //提交信息
var ajax = new $ax(Feng.ctxPath + "/dept/update", function(data){ var ajax = new $ax(Feng.ctxPath + "/dept/update", function(data){
Feng.success("修改成功!"); Feng.success("修改成功!");
...@@ -133,6 +173,8 @@ function onBodyDown(event) { ...@@ -133,6 +173,8 @@ function onBodyDown(event) {
} }
$(function() { $(function() {
Feng.initValidator("deptInfoForm", DeptInfoDlg.validateFields);
var ztree = new $ZTree("parentDeptMenuTree", "/dept/tree"); var ztree = new $ZTree("parentDeptMenuTree", "/dept/tree");
ztree.bindOnClick(DeptInfoDlg.onClickDept); ztree.bindOnClick(DeptInfoDlg.onClickDept);
ztree.init(); ztree.init();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment