tagsInput的非可见字符验证提取到common.js中

This commit is contained in:
wangxin
2018-08-17 15:28:15 +08:00
parent 05fca7be1b
commit cc56170346
2 changed files with 22 additions and 16 deletions

View File

@@ -115,20 +115,9 @@
} }
} }
}); });
var hasInvisibleCharTags=[]; var flag1=validateInvisibleCharTag();
var reg = new RegExp(/\t|\r|\n/); if(flag){
console.log($(".tagsinput").find(".tag").length); flag=flag1;
$(".tagsinput").find(".tag").each(function(){
var text=$(this).children("span").text();
if (text.match(reg)) {
hasInvisibleCharTags.push("'"+text+"'");
flag = false;
}
});
if(hasInvisibleCharTags.length==1){
$(".tagsinput").parents(".col-md-6").next("div").html("<label class='error'>"+$.validator.messages.hasInvisibleChar.replace("{0}",hasInvisibleCharTags.join(","))+"</label>");
}else if(hasInvisibleCharTags.length>=1){
$(".tagsinput").parents(".col-md-6").next("div").html("<label class='error'>"+$.validator.messages.haveInvisibleChar.replace("{0}",hasInvisibleCharTags.join(","))+"</label>");
} }
if(flag){ if(flag){
//将disable属性的元素删除 //将disable属性的元素删除
@@ -136,7 +125,6 @@
$(this).remove(); $(this).remove();
}); });
$("input[name$='exprType']").attr("disabled",false); $("input[name$='exprType']").attr("disabled",false);
console.log(7777);
loading('onloading...'); loading('onloading...');
form.submit(); form.submit();
}else{ }else{

View File

@@ -1101,4 +1101,22 @@ var importCfg=function(){
} }
$("#import_modal").modal('hide');//导入文件隐藏 $("#import_modal").modal('hide');//导入文件隐藏
$("#importForm1").submit(); $("#importForm1").submit();
} }
var validateInvisibleCharTag=function(){
var hasInvisibleCharTags=[];
var reg = new RegExp(/\t|\r|\n/);
$(".tagsinput").find(".tag").each(function(){
var text=$(this).children("span").text();
if (text.match(reg)) {
hasInvisibleCharTags.push("'"+text.trim()+"'");
}
});
if(hasInvisibleCharTags.length==1){
$(".tagsinput").parents(".col-md-6").next("div").html("<label class='error'>"+$.validator.messages.hasInvisibleChar.replace("{0}",hasInvisibleCharTags.join(","))+"</label>");
return false;
}else if(hasInvisibleCharTags.length>=1){
$(".tagsinput").parents(".col-md-6").next("div").html("<label class='error'>"+$.validator.messages.haveInvisibleChar.replace("{0}",hasInvisibleCharTags.join(","))+"</label>");
return false;
}
return true;
}