表单
<div class="we_cell_form_box" id="form_container"></div>
var formElements = [ {label:'Require',name:'require',events:'blur,focus',require:true}, {label:'URL',name:'url',expression:'url',value:'http://'}, {label:'密码',name:'pwd',type:'password',expression:'',require:true,events:'blur'}, {label:'确认密码',name:'pwd2',type:'password',expression:'equal-pwd',require:true,events:'blur'}, {label:'Email',name:'email',expression:'email',type:'autocomplete',placeholder:'请输入Email', acConfig:{ title:'请选择邮箱类型', search_parse:function(data){ var v = this.val(); var i=v.indexOf('@'); if(i>=0){ var tail = v.substr(i); if(data.indexOf(tail)>=0){ return v.substr(0,i)+data; }else{ return null; } }else{ return v+data; } }, ds:['@126.com','@163.com','@gmail.com','@sohu.com'] } }, {label:'数字',name:'number',expression:'number'}, {label:'整数',name:'int',expression:'int'}, {label:'双精度',name:'float',expression:'float'}, {label:'日期',name:'date',expression:'date-d'}, {label:'最大值',name:'max',expression:'max-100'}, {label:'最小值',name:'min',expression:'min-50'}, {label:'数字范围',name:'range',expression:'range-50-100'}, {label:'自定义',name:'custom_valid',events:'blur',expression:function(e){ var s=e.val(); if(s!='ok'){ return {valid:false,error_msg:'输入错误,请输入ok'}; }else{ return {valid:true}; } }}, {label:'性别',name:'sex',type:'select',data:[{text:'男',value:'male'},{text:'女',value:'female'}]}, {label:'隐藏',name:'hidden',expression:'number',hidden:true}, {label:'手机号',name:'phone',expression:function(){return '^1(3|5|8)\\d{9}$'},events:'blur',require:true,success:'输入正确了哦',error:'手机号格式不正确',info:'请输入您的手机号'}, {label:'手机号码',name:'content',type:'content',value:'
136****9963
'}, {label:'发送验证码',name:'send_code',type:'button',value:'发送',click:function(){console.log(this);}}, {label:'身份证号',name:'card',expression:'id_card',events:'blur'} ]; var form = $we.widget.add("Form", $('#form_container'), { form_elements:formElements, commit:function(){ $we.comp.alert("提交表单喽"); } }); $('#form_container').show();
$we.form.valid('#form_container');
$we.form.valid("input[name='require']");
console.log($we.form.getData('#form_container'));
console.log($we.form.getData("input[name='require']"));