校验参数(options):
validateOptions={
rules:"required:true,minlength:5",
errMsg:"required:'名称不能为空。',minlength:'名称至少5字符!'",
validatetrigger:"onfocus,onblur,onkeyup",
errorLabelPosition:"right"
}
validateOptions=
{
rules:"required:true,min:3",
errMsg:"required:'数值不能为空。',min:'数值必须大于3!'",
validatetrigger:"onfocus,onblur,onkeyup"
}
validateOptions={
rules:"required:true",
errMsg:"required::'家乡不能为空!'"
}
validateOptions={rules:"required:true",
errMsg:"required:'内容不能为空。'",
validatetrigger:"onfocus,onblur,onkeyup",
remoteRule:"url:'/validator/docheck.do',
type:'POST',
data:{
billName:function(){
return waf('#xxx"+contentIndex + "').val()},
status:function(){return 'saved'}
}"
}
validateOptions={
rules:"required:true,minlength:20",
errMsg:"required:'文本区不能为空。',
minlength:'不能小于20字符。'",
validatetrigger:"onfocus,onblur,onkeyup"
}
validateOptions={
rules:"required:true,minlength:10",
errMsg:"required:'多语言文本区不能为空。',
minlength:'不能小于10字符。'",
validatetrigger:"onfocus,onblur,onkeyup"
}
validateOptions={
rules:"required:true",
errMsg:"required:'日期不能为空。'",
customvalidate:"rqmethod",
validatetrigger:"onfocus,onblur,onkeyup"
}
validateOptions={
rules:"required:true",
errMsg:"required:'必须选择一项。'",
validatetrigger:"click,datachange",
customvalidate:"selmethod",
validateOnSumbit:"false",
errorShowMode:"float"
}
validateOptions={rules:"required:true,minlength:2",
errMsg:"required:'必须选择哦。',
minlength:'至少选择2项!'",
validatetrigger:"click,datachange"
}
validateOptions={
rules:"required:true",
errMsg:"required:'必须选择哦。'",
errorLabelPosition:"right"
}
validateOptions={
rules:"required:true",
errMsg:"required:'必须选择哦。'",
errorLabelPosition:"right"
}
核心代码片段:
//创建input添加到labelContainer
var options = {id:"xxx"+contentIndex,name:"xxx"+contentIndex};
var newDom = waf.createDOM("text", options);
//lcDom为labelContainer
lcDom.wafLabelContainer('appendChildren',newDom);
waf.initComponent("text", options, newDom);
//初始化左侧的校验参数到目标控件
waf.initComponent("validator",validateOptions,newDom);
//根据校验规则给labelContainer前加*号
lcDom.wafLabelContainer('initRequiredMask');
//创建numberField添加到labelContainer
var options = {id:"xxx"+contentIndex,name:"xxx"+contentIndex};
var newDom = waf.createDOM("numberField", options);
//lcDom为labelContainer
lcDom.wafLabelContainer('appendChildren',newDom);
waf.initComponent("numberField", options, newDom);
//初始化左侧的校验参数到目标控件
waf.initComponent("validator",validateOptions,newDom);
//根据校验规则给labelContainer前加*号
lcDom.wafLabelContainer('initRequiredMask');
//创建promptBox添加到labelContainer
box_id = "家乡"+contentIndex;
var options = {id:box_id,name:box_id,displayFormat:"{city}",submitField:box_id + '_el'};
var newDom = waf.createDOM("promptBox", options);
//lcDom是labelContainer
lcDom.wafLabelContainer('appendChildren',newDom);
waf.initComponent("promptBox", options, newDom);
var promptOptions = {ajaxType:'POST',autoCompleteItem:'name',parentId:box_id,
dataUrl:'/myweb/f7/grid/data.do',minlength:0}
var promptQuickDom = waf.createDOM('promptGrid', promptOptions);
waf.initComponent('promptGrid', promptOptions, promptQuickDom);
lcDom.append("("+box_id+")");
//初始化左侧的校验参数到目标控件
waf.initComponent("validator",validateOptions,newDom);
//根据校验规则给labelContainer前加*号
lcDom.wafLabelContainer('initRequiredMask');
//创建multiLangBox添加到labelContainer
var options = {id:"xxx"+contentIndex,name:"xxx"+contentIndex};
var newDom = waf.createDOM("multiLangBox", options);
//lcDom是labelContainer
lcDom.wafLabelContainer('appendChildren',newDom);
waf.initComponent("multiLangBox", options, newDom);
//初始化左侧的校验参数到目标控件
waf.initComponent("validator",validateOptions,newDom);
//根据校验规则给labelContainer前加*号
lcDom.wafLabelContainer('initRequiredMask');
//创建textarea添加到labelContainer
var options = {id:"xxx"+contentIndex,name:"xxx"+contentIndex};
var newDom = waf.createDOM("textarea", options);
//lcDom是labelContainer
lcDom.wafLabelContainer('appendChildren',newDom);
waf.initComponent("textarea", options, newDom);
//初始化左侧的校验参数到目标控件
waf.initComponent("validator",validateOptions,newDom);
//根据校验规则给labelContainer前加*号
lcDom.wafLabelContainer('initRequiredMask');
//创建multiLangArea添加到labelContainer
var options = {id:"xxx"+contentIndex,name:"xxx"+contentIndex};
var newDom = waf.createDOM("multiLangArea", options);
//lcDom是labelContainer
lcDom.wafLabelContainer('appendChildren',newDom);
waf.initComponent("multiLangArea", options, newDom);
//初始化左侧的校验参数到目标控件
waf.initComponent("validator",validateOptions,newDom);
//根据校验规则给labelContainer前加*号
lcDom.wafLabelContainer('initRequiredMask');
//创建datePicker添加到labelContainer
var options = {id:"xxx"+contentIndex,name:"xxx"+contentIndex,
dateFormat:"yy/mm/dd"};
var newDom = waf.createDOM("datePicker", options);
//lcDom是labelContainer
lcDom.wafLabelContainer('appendChildren',newDom);
waf.initComponent("datePicker", options, newDom);
//初始化左侧的校验参数到目标控件
waf.initComponent("validator",validateOptions,newDom);
//根据校验规则给labelContainer前加*号
lcDom.wafLabelContainer('initRequiredMask');
//创建select添加到labelContainer
var options = {id:"xxx"+contentIndex,name:"xxx"+contentIndex,
urlSource:"/select/source.do"};
var newDom = waf.createDOM("select", options);
//lcDom是labelContainer
lcDom.wafLabelContainer('appendChildren',newDom);
waf.initComponent("select", options, newDom);
//初始化左侧的校验参数到目标控件
waf.initComponent("validator",validateOptions,newDom);
//根据校验规则给labelContainer前加*号
lcDom.wafLabelContainer('initRequiredMask');
//创建checkBox添加到labelContainer
//lcDom是labelContainer
var options = {id:"xxx"+contentIndex,name:"xxx"+contentIndex,label:"选项一",value:0};
var newDom = waf.createDOM("checkbox", options);
lcDom.wafLabelContainer('appendChildren',newDom);
waf.initComponent("checkbox", options, newDom);
var options = {id:"xxx"+contentIndex+1,name:"xxx"+contentIndex,label:"选项二",value:1};
var newDom2 = waf.createDOM("checkbox", options);
lcDom.wafLabelContainer('appendChildren',newDom2);
waf.initComponent("checkbox", options, newDom2);
var options = {id:"xxx"+contentIndex+2,name:"xxx"+contentIndex,label:"选项三",value:2};
var newDom3 = waf.createDOM("checkbox", options);
lcDom.wafLabelContainer('appendChildren',newDom3);
waf.initComponent("checkbox", options, newDom3);
//只需要将上面相同name的checkbox的第一个注册校验规则即可
waf.initComponent("validator",validateOptions,newDom);
//根据校验规则给labelContainer前加*号
lcDom.wafLabelContainer('initRequiredMask');
//创建radioGroup添加到labelContainer
var options = {id:"xxx"+contentIndex,name:"xxx"+contentIndex,
items:[{"alias":"男","value":"male"},
{"alias":"女","value":"female"}]};
var newDom = waf.createDOM("radioGroup", options);
//lcDom是labelContainer
lcDom.wafLabelContainer('appendChildren',newDom);
waf.initComponent("radioGroup", options, newDom);
//初始化左侧的校验参数到目标控件
waf.initComponent("validator",validateOptions,newDom);
//根据校验规则给labelContainer前加*号
lcDom.wafLabelContainer('initRequiredMask');
//创建radio添加到labelContainer,lcDom是labelContainer
var options = {id:"xxx"+contentIndex,name:"xxx"+contentIndex,
label:"选项一",value:0};
var newDom = waf.createDOM("radio", options);
lcDom.wafLabelContainer('appendChildren',newDom);
waf.initComponent("radio", options, newDom);
var options = {id:"xxx"+contentIndex+1,name:"xxx"+contentIndex,
label:"选项二",value:1};
var newDom2 = waf.createDOM("radio", options);
lcDom.wafLabelContainer('appendChildren',newDom2);
waf.initComponent("radio", options, newDom2);
var options = {id:"xxx"+contentIndex+2,name:"xxx"+contentIndex,
label:"选项三",value:2};
var newDom3 = waf.createDOM("radio", options);
lcDom.wafLabelContainer('appendChildren',newDom3);
waf.initComponent("radio", options, newDom3);
//只需要将上面相同name的radio的第一个注册校验规则即可
waf.initComponent("validator", options, newDom);
//根据校验规则给labelContainer前加*号
lcDom.wafLabelContainer('initRequiredMask');