js bootstrapValidator自己写验证方法callback方法

$('#registrationForm').bootstrapValidator({
	   feedbackIcons: {/*input状态样式图片*/
           valid: 'glyphicon glyphicon-ok',
           invalid: 'glyphicon glyphicon-remove',
           validating: 'glyphicon glyphicon-refresh'
       },
		fields: {
			categoryName: {
				trigger: 'blur',
				container: '#categoryNameSpan',
	        	validators: {
					stringLength: {//检测长度
		                    max: 8,
		                    message: '栏目名称控制在8个汉子以内容,请精简'
		                },
	                callback:{
	                	callback: function (value, validator) {
	                		var res = true;
	                		if(value == "")
	                		{
	                			return {valid: false, message: '名称不能为空,请输入名称!'};
	                		}
	                		if(value != "")
                			{
                				$.ajax({ 
	                	        	url:'check_section_name', 
	                	        	type:"post",
	                	        	data: {sectionName:function(){return $('#categoryName').val();},id:function(){return $('#categoryId').val();}},
	                	        	dataType:"json",
	                	        	async: false,
	                	        	success: function(msg)
	                	        	{
	                	        		var result=eval('(' + msg + ')');
	                	        		if(result.valid == true)
	                	        		{
	                	        			res = true;
	                	        		}
	                	        		else
	                	        		{
	                	        			res = {valid: false, message: '该栏目名称已存在,请重新填写!'};
	                	        		}
	                	        		return res;
	                	            }
	                			});	
                				return res;
                			}
	                	}
	                }
				}
			}
		}
	})

  

猜你喜欢

转载自www.cnblogs.com/guilf/p/9489116.html