var regform = new Ext.FormPanel({
monitorValid:true,
labelWidth:80,
baseCls: 'x-plain',
width:150,
defaultType:'textfield',
items:[{
fieldLabel:'用户名',
id:'txtUserName',
name:'username',
allowBlank:false,
blankText:'用户名不能为空!',
validator:CheckUserName,//指定验证器
invalidText:'用户名已经被注册!'
},{
inputType:'password',
fieldLabel:'密码',
name:'userpassword',
allowBlank:false,
blankText:'密码不能为空!'
},{
inputType:'password',
fieldLabel:'确认密码',
name:'cuserpassword',
allowBlank:false,
blankText:'确认密码不能为空!',
invalidText:'两次密码不一致!',
validator:function(){
if(Ext.get('userpassword').dom.value == Ext.get('cuserpassword').dom.value)
return true;
return false;
}
},{
fieldLabel: '电子邮件',
allowBlank:false,
blankText:'电子邮件不能为空',
regex:/^\d+$/, //正则表达式,这里没有详细写,只是验证了数字
regexText:'电子邮件格式错误!'
}]}
这样怎么和后台交互呢?谢谢!
monitorValid:true,
labelWidth:80,
baseCls: 'x-plain',
width:150,
defaultType:'textfield',
items:[{
fieldLabel:'用户名',
id:'txtUserName',
name:'username',
allowBlank:false,
blankText:'用户名不能为空!',
validator:CheckUserName,//指定验证器
invalidText:'用户名已经被注册!'
},{
inputType:'password',
fieldLabel:'密码',
name:'userpassword',
allowBlank:false,
blankText:'密码不能为空!'
},{
inputType:'password',
fieldLabel:'确认密码',
name:'cuserpassword',
allowBlank:false,
blankText:'确认密码不能为空!',
invalidText:'两次密码不一致!',
validator:function(){
if(Ext.get('userpassword').dom.value == Ext.get('cuserpassword').dom.value)
return true;
return false;
}
},{
fieldLabel: '电子邮件',
allowBlank:false,
blankText:'电子邮件不能为空',
regex:/^\d+$/, //正则表达式,这里没有详细写,只是验证了数字
regexText:'电子邮件格式错误!'
}]}
这样怎么和后台交互呢?谢谢!
在验证的函数里用Ext.Ajax请求提交你的用户名,服务器返回JSON对象,客户端通过response.responsetext转换为JSON对象,判断用户是否可用
regform .getForm().submit({
waitMsg : '正在处理......',
url:'后台交互地址可以带你要的参数',
method : 'POST',
success: function(){
regform.form.reset();
},
failure : function(){
regform.form.reset();
Ext.MessageBox.alert('警告',"操作失败!");
}
});更多的用法参看ext的api文档上面说的很详细了
text:'查看是否可用',
handler:function(){
var username=documnet.getElementById("username");
var userpassword=documnet.getElementById("userpassword");
var cuserpassword=documnet.getElementById("cuserpassword");
if(userpassword.equals(cuserpassword)){
Ext.Ajax.request({
url:'/action.do',
params:{username:username,
},
method:'POST',
waitMsg:"正在更新,请稍侯...",
success:function() {
Ext.Msg.alert('提示信息',' 用户名可以使用! ');
},
failure:function(){
Ext.Msg.alert('提示信息',' 用户名已经被使用! ');
}
});
}else{
alert("两次密码输入不一致!");
}
}
}]
反正肯定是要用AJAX异步提交到后台服务器校验