添加表单提交时验证结果,防止firefox在校验不通过时仍能提交的现象

This commit is contained in:
zhangshilin
2018-04-02 18:33:14 +08:00
parent 7eb75d40b6
commit 07ee4cec82
7 changed files with 59 additions and 23 deletions

View File

@@ -55,7 +55,7 @@ public class ServiceDictInfoController extends BaseController {
* @param model
* @return
*/
@RequiresPermissions(value={"basics:classification:view","basics:attribute:view","basics:label:view","basics:classificationattribute:edit"},logical=Logical.OR)
@RequiresPermissions(value={"basics:classification:view","basics:attribute:view","basics:label:view"},logical=Logical.OR)
@RequestMapping(value = {"list", ""})
public String list(String itType, ServiceDictInfo serviceDictInfo,HttpServletRequest request, HttpServletResponse response, Model model) {
//处理数据

View File

@@ -5,7 +5,18 @@
<link rel="stylesheet" type="text/css" href="${ctxStatic}/pages/css/dictInfo.css" />
<script type="text/javascript" src="${ctxStatic}/pages/scripts/dict.js"></script>
<title></title>
<style type="text/css">
label.errorShow {
background: url("${ctxStatic}/global/plugins/jquery-validation/1.11.0/images/unchecked.gif") no-repeat 0 0;
padding-left: 18px;
padding-bottom: 2px;
font-weight: bold;
color: #ea5200;
margin-left: 10px;
}
</style>
<script type="text/javascript">
var validateForm;
//上级选择数据类型自动改变
function serviceDictInfoTreeselectCallBack(){
var parent = $("#serviceDictInfoId").val();
@@ -35,9 +46,9 @@
data:{parentId:$(".singleClass").val(),currentId:'${serviceDictInfo.serviceDictId}'},
success:function(data){
if(data){
$(".errorShow").hide();
$(".errorShow").prop("style","display:none");
}else{
$(".errorShow").show();
$(".errorShow").prop("style","display:block");
}
flaelNoSure = data;
}
@@ -50,7 +61,7 @@
jQuery.validator.addMethod("typeSame",function(value,element){
var flagTypeSame=false;
var parentCondition = $("#serviceDictInfoId").val();
var childCondition = $("#itemTypeCheckChild option:selected").val();
var childCondition = value;
$.ajax({
type:'post',
async:false,
@@ -62,6 +73,22 @@
});
return flagTypeSame;
},"请选择正确的数据类型");
//与下级是否一致
jQuery.validator.addMethod("childrenType",function(value,element){
var flagChildTypeSame=false;
var currentIdAsP=${serviceDictInfo.serviceDictId}
$.ajax({
type:'post',
async:false,
url:'${ctx}/basics/serviceDictInfo/ajaxChildrenType',
data:{parent:currentIdAsP,itemType:value},
success:function(data){
flagChildTypeSame=data;
}
});
return flagChildTypeSame;
},"该配置包含下级配置,数据类型更改后与子类不一致");
//校验叶子节点有下级不得更改为叶子节点
jQuery.validator.addMethod("leafChange",function(value,element){
var flagLeafChange=false;
@@ -78,7 +105,7 @@
},"该配置包含下级配置,不得改为叶子节点");
$("#name").focus();
$("#inputForm").validate({
validateForm=$("#inputForm").validate({
rules: {
'itemCode':{
required:true,
@@ -89,10 +116,11 @@
required:true,
maxlength:64
},
'itemType':{
remote:'${ctx}/basics/serviceDictInfo/ajaxChildrenType?parent=${serviceDictInfo.serviceDictId}',
'itemType':{
childrenType:true,
//remote:'${ctx}/basics/serviceDictInfo/ajaxChildrenType?parent=${serviceDictInfo.serviceDictId}',
typeSame:true
},
},
'isLeaf':{
leafChange:true
},
@@ -111,10 +139,11 @@
required:'<spring:message code="required"/>',
maxlength:'<spring:message code="maxlength_64"/>'
},
'itemType':{
remote:'<spring:message code="typeChild"/>',
'itemType':{
childrenType:'<spring:message code="typeChild"/>',
//remote:'<spring:message code="typeChild"/>',
typeSame:'<spring:message code="typeSame"/>'
},
},
'isLeaf':{
leafChange:'<spring:message code="leafChange"/>'
},
@@ -128,6 +157,9 @@
if(!res){
return false;
}
if(!validateForm.form()){
return false;
}
loading('<spring:message code="submitting"/>');
form.submit();
},
@@ -189,7 +221,7 @@
<c:set var="fatherName"><spring:message code="root_node"/></c:set>
<sys:treeselect id="serviceDictInfo" name="parent.serviceDictId" value="${serviceDictInfo.parent.serviceDictId}" labelName="parent.itemValue" labelValue="${serviceDictInfo.parent.serviceDictId eq '0'?fatherName:fns:getServiceDictInfoById(serviceDictInfo.parent.serviceDictId).itemValue}"
title="菜单" url="/basics/serviceDictInfo/treeData?itType=${itType}" extId="${serviceDictInfo.serviceDictId}" cssClass="required form-control"/>
<label class="error errorShow" style="display: none;"><spring:message code="isLevelNoSure"/></label>
<label class="errorShow" style="display: none;"><spring:message code="isLevelNoSure"/></label>
</div>
</div>
<div class="form-group">
@@ -253,7 +285,5 @@
</div>
</div>
</body>
</html>

View File

@@ -6,6 +6,7 @@
<script type="text/javascript" src="${ctxStatic}/pages/scripts/dict.js"></script>
<title>配置管理</title>
<script type="text/javascript">
var validateForm;
//上级选择数据类型自动改变
function sysDictInfoTreeselectCallBack(){
var parent = $("#sysDictInfoId").val();
@@ -41,7 +42,7 @@
return flag;
},"请选择正确的数据类型");
//校验叶子节点有下级不得更改为叶子节点
//校验叶子节点,有下级不得更改为叶子节点
jQuery.validator.addMethod("leafChange",function(value,element){
var flag=false;
$.ajax({
@@ -57,7 +58,7 @@
},"该配置包含下级配置,不得改为叶子节点");
$("#name").focus();
$("#inputForm").validate({
validateForm = $("#inputForm").validate({
rules: {
'itemCode':{
required:true,
@@ -104,6 +105,9 @@
},
submitHandler: function(form){
if(!validateForm.form()){
return false;
}
loading('<spring:message code="submitting"/>');
form.submit();
},

View File

@@ -246,7 +246,7 @@
<div class="form-group">
<label>&nbsp;</label>
<input id="editEndDate" name="editEndDate" type="text" readonly="readonly" maxlength="20" class="form-control Wdate"
value="<fmt:formatDate value="${sysDictInfo.editEndDate}" pattern="yyyy-MM-dd"/>" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',isShowClear:true});"/>
value="<fmt:formatDate value="${sysDictInfo.editEndDate}" pattern="yyyy-MM-dd HH:mm:ss"/>" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',isShowClear:true});"/>
</div>

View File

@@ -6,6 +6,7 @@
<script type="text/javascript" src="${ctxStatic}/pages/scripts/specificServiceForm/specificServiceFormCfg.js"></script>
<title></title>
<script type="text/javascript">
var validateForm;
$(document).ready(function() {
jQuery.validator.addMethod("maxValue", function(value, element) {
return value >=0&&value<2100000000;
@@ -41,7 +42,7 @@
},"该配置包含下级配置,不得改为叶子节点");
$("#name").focus();
$("#inputForm").validate({
validateForm = $("#inputForm").validate({
rules:{
specServiceId:{
required:true,
@@ -91,7 +92,7 @@
},
submitHandler: function(form){
if(!validateItem()) {
if(!validateForm.form()) {
return false;
}
loading('正在提交,请稍等...');

View File

@@ -212,7 +212,7 @@
<div class="form-group">
<label><spring:message code="operate_time"/></label>
<input id="beginDate" name="beginDate" type="text" readonly="readonly" maxlength="20" class="form-control Wdate"
value="<fmt:formatDate value="${specificServiceCfg.beginDate}" pattern="yyyy-MM-dd"/>" onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:true});"/>
value="<fmt:formatDate value="${specificServiceCfg.beginDate}" pattern="yyyy-MM-dd HH:mm:ss"/>" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',isShowClear:true});"/>
</div>
</div>
@@ -222,7 +222,7 @@
<div class="form-group">
<label>&nbsp;</label>
<input id="endDate" name="endDate" type="text" readonly="readonly" maxlength="20" class="form-control Wdate"
value="<fmt:formatDate value="${specificServiceCfg.endDate}" pattern="yyyy-MM-dd"/>" onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:true});"/>
value="<fmt:formatDate value="${specificServiceCfg.endDate}" pattern="yyyy-MM-dd HH:mm:ss"/>" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',isShowClear:true});"/>
</div>

View File

@@ -7,6 +7,7 @@
<script type="text/javascript" src="${ctxStatic}/pages/scripts/dict.js"></script>
<title></title>
<script type="text/javascript">
var validateForm;
function selectP(){
$("label[for='specServiceId']").hide();
}
@@ -75,7 +76,7 @@ function selectP(){
return true;
}, "请填写正确的数值");
$("#name").focus();
$("#inputForm")
validateForm = $("#inputForm")
.validate(
{
rules : {
@@ -178,7 +179,7 @@ function selectP(){
},
submitHandler : function(form) {
if (!validateItem()) {
if (!validateForm.form()) {
return false;
}
loading('正在提交,请稍等...');