Commit cccaa913 by naan1993

通知管理增加表单验证

parent 61f1562f
@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="noticeInfoForm">
<input type="hidden" id="id" value=""> <input type="hidden" id="id" value="">
...@@ -10,14 +10,14 @@ ...@@ -10,14 +10,14 @@
<div class="form-group"> <div class="form-group">
<label class="col-sm-1 control-label">标题</label> <label class="col-sm-1 control-label">标题</label>
<div class="col-sm-11"> <div class="col-sm-11">
<input class="form-control" id="title" type="text"> <input class="form-control" id="title" name="title" type="text">
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label class="col-sm-1 control-label">内容</label> <label class="col-sm-1 control-label">内容</label>
<div class="col-sm-11"> <div class="col-sm-11">
<textarea class="form-control" id="content" type="text" style="height: 150px;"></textarea> <textarea class="form-control" id="content" name="content" type="text" style="height: 150px;"></textarea>
</div> </div>
</div> </div>
</div> </div>
......
@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="noticeInfoForm">
<input type="hidden" id="id" value="${notice.id}"> <input type="hidden" id="id" value="${notice.id}">
...@@ -10,14 +10,14 @@ ...@@ -10,14 +10,14 @@
<div class="form-group"> <div class="form-group">
<label class="col-sm-1 control-label">标题</label> <label class="col-sm-1 control-label">标题</label>
<div class="col-sm-11"> <div class="col-sm-11">
<input class="form-control" id="title" type="text" value="${notice.title}"> <input class="form-control" id="title" name="title" type="text" value="${notice.title}">
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label class="col-sm-1 control-label">内容</label> <label class="col-sm-1 control-label">内容</label>
<div class="col-sm-11"> <div class="col-sm-11">
<textarea class="form-control" id="content" type="text" style="height: 150px;">${notice.content}</textarea> <textarea class="form-control" id="content" name="content" type="text" style="height: 150px;">${notice.content}</textarea>
</div> </div>
</div> </div>
</div> </div>
......
...@@ -2,7 +2,23 @@ ...@@ -2,7 +2,23 @@
* 初始化通知详情对话框 * 初始化通知详情对话框
*/ */
var NoticeInfoDlg = { var NoticeInfoDlg = {
noticeInfoData : {} noticeInfoData : {},
validateFields: {
title: {
validators: {
notEmpty: {
message: '标题不能为空'
}
}
},
content: {
validators: {
notEmpty: {
message: '内容不能为空'
}
}
}
}
}; };
/** /**
...@@ -48,6 +64,15 @@ NoticeInfoDlg.collectData = function() { ...@@ -48,6 +64,15 @@ NoticeInfoDlg.collectData = function() {
} }
/** /**
* 验证数据是否为空
*/
NoticeInfoDlg.validate = function () {
$('#noticeInfoForm').data("bootstrapValidator").resetForm();
$('#noticeInfoForm').bootstrapValidator('validate');
return $("#noticeInfoForm").data('bootstrapValidator').isValid();
};
/**
* 提交添加 * 提交添加
*/ */
NoticeInfoDlg.addSubmit = function() { NoticeInfoDlg.addSubmit = function() {
...@@ -55,6 +80,10 @@ NoticeInfoDlg.addSubmit = function() { ...@@ -55,6 +80,10 @@ NoticeInfoDlg.addSubmit = function() {
this.clearData(); this.clearData();
this.collectData(); this.collectData();
if (!this.validate()) {
return;
}
//提交信息 //提交信息
var ajax = new $ax(Feng.ctxPath + "/notice/add", function(data){ var ajax = new $ax(Feng.ctxPath + "/notice/add", function(data){
Feng.success("添加成功!"); Feng.success("添加成功!");
...@@ -75,6 +104,10 @@ NoticeInfoDlg.editSubmit = function() { ...@@ -75,6 +104,10 @@ NoticeInfoDlg.editSubmit = function() {
this.clearData(); this.clearData();
this.collectData(); this.collectData();
if (!this.validate()) {
return;
}
//提交信息 //提交信息
var ajax = new $ax(Feng.ctxPath + "/notice/update", function(data){ var ajax = new $ax(Feng.ctxPath + "/notice/update", function(data){
Feng.success("修改成功!"); Feng.success("修改成功!");
...@@ -88,5 +121,5 @@ NoticeInfoDlg.editSubmit = function() { ...@@ -88,5 +121,5 @@ NoticeInfoDlg.editSubmit = function() {
} }
$(function() { $(function() {
Feng.initValidator("noticeInfoForm", NoticeInfoDlg.validateFields);
}); });
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