Commit 61f1562f by naan1993

菜单管理增加表单验证

parent d4cf3ae3
@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="menuInfoForm">
<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="menuInfoForm">
<input type="hidden" id="id" value="${menu.id}"> <input type="hidden" id="id" value="${menu.id}">
<input type="hidden" id="ismenuValue" value="${menu.ismenu}"> <input type="hidden" id="ismenuValue" value="${menu.ismenu}">
......
...@@ -3,7 +3,37 @@ ...@@ -3,7 +3,37 @@
*/ */
var MenuInfoDlg = { var MenuInfoDlg = {
menuInfoData: {}, menuInfoData: {},
ztreeInstance: null ztreeInstance: null,
validateFields: {
name: {
validators: {
notEmpty: {
message: '菜单名称不能为空'
}
}
},
code: {
validators: {
notEmpty: {
message: '菜单编号不能为空'
}
}
},
pcodeName: {
validators: {
notEmpty: {
message: '父菜单不能为空'
}
}
},
url: {
validators: {
notEmpty: {
message: '请求地址不能为空'
}
}
}
}
}; };
/** /**
...@@ -49,6 +79,15 @@ MenuInfoDlg.collectData = function () { ...@@ -49,6 +79,15 @@ MenuInfoDlg.collectData = function () {
} }
/** /**
* 验证数据是否为空
*/
MenuInfoDlg.validate = function () {
$('#menuInfoForm').data("bootstrapValidator").resetForm();
$('#menuInfoForm').bootstrapValidator('validate');
return $("#menuInfoForm").data('bootstrapValidator').isValid();
}
/**
* 提交添加用户 * 提交添加用户
*/ */
MenuInfoDlg.addSubmit = function () { MenuInfoDlg.addSubmit = function () {
...@@ -56,6 +95,10 @@ MenuInfoDlg.addSubmit = function () { ...@@ -56,6 +95,10 @@ MenuInfoDlg.addSubmit = function () {
this.clearData(); this.clearData();
this.collectData(); this.collectData();
if (!this.validate()) {
return;
}
//提交信息 //提交信息
var ajax = new $ax(Feng.ctxPath + "/menu/add", function (data) { var ajax = new $ax(Feng.ctxPath + "/menu/add", function (data) {
Feng.success("添加成功!"); Feng.success("添加成功!");
...@@ -76,6 +119,10 @@ MenuInfoDlg.editSubmit = function () { ...@@ -76,6 +119,10 @@ MenuInfoDlg.editSubmit = function () {
this.clearData(); this.clearData();
this.collectData(); this.collectData();
if (!this.validate()) {
return;
}
//提交信息 //提交信息
var ajax = new $ax(Feng.ctxPath + "/menu/edit", function (data) { var ajax = new $ax(Feng.ctxPath + "/menu/edit", function (data) {
Feng.success("修改成功!"); Feng.success("修改成功!");
...@@ -105,11 +152,17 @@ MenuInfoDlg.showMenuSelectTree = function () { ...@@ -105,11 +152,17 @@ MenuInfoDlg.showMenuSelectTree = function () {
}; };
$(function () { $(function () {
Feng.initValidator("menuInfoForm", MenuInfoDlg.validateFields);
var ztree = new $ZTree("pcodeTree", "/menu/selectMenuTreeList"); var ztree = new $ZTree("pcodeTree", "/menu/selectMenuTreeList");
ztree.bindOnClick(MenuInfoDlg.onClickDept); ztree.bindOnClick(MenuInfoDlg.onClickDept);
ztree.init(); ztree.init();
MenuInfoDlg.ztreeInstance = ztree; MenuInfoDlg.ztreeInstance = ztree;
//初始化是否是菜单 //初始化是否是菜单
$("#ismenu").val($("#ismenuValue").val()); if($("#ismenuValue").val() == undefined){
$("#ismenu").val(0);
}else{
$("#ismenu").val($("#ismenuValue").val());
}
}); });
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