首先在js中添加,实现自定义验证的规则:
$.extend($.fn.validatebox.defaults.rules, {
minLength: {
validator: function(value, param){
return value.length >= param[0];
},
message: '请输入至少(2)个字符.'
}
接着在html的easyui-validatebox中添加,有两种方式:
1. <textarea class="easyui-validatebox"
id="<s:property value='#field.name'/>"
name="map.<s:property value='#field.name'/>"
data-options="validType:'maxLength[<s:property value='#field.length'/>]'"
invalidMessage="<s:property value='#field.text'/>不能输入超过<s:property value='#field.length'/>个字符"
rows="5" cols="67"></textarea>
2. <textarea class="easyui-validatebox"
id="<s:property value='#field.name'/>"
name="map.<s:property value='#field.name'/>"
validType:'maxLength[<s:property value='#field.length'/>]'
invalidMessage="<s:property value='#field.text'/>不能输入超过<s:property value='#field.length'/>个字符"
rows="5" cols="67"></textarea>
然后在form提交的时候,加上验证:
$('#'+tabName+'Form').form('submit',{
url : 'insertTabTemplateData.do?tab='+tabId+'&tableName='+tabName,
onSubmit: function(){
return $(this).form('validate');
},
success : function(data){
if(data == "success"){
$('#'+tabName+'Win').window('close');
$('#'+tabName).datagrid('load');
$.messager.show({title:'操作提示',msg:'新增成功!',showType:'show'});
}else{
$.messager.show({title:'操作提示',msg:'新增失败!',showType:'show'});
}
}
});