---
title: "一个比较完整的Ext注册表单例子"
author: "nieli"
date: "2009-11-27T11:37:26Z"
tags: ["Ajax", "EXT", "Mobile", "json", "thread"]
slug: "ext"
draft: false
lastmod: "2009-11-27T11:37:26Z"
id: 531045
url: "https://nieli.iteye.com/blog/531045"
---

转自：[http://www.tech-q.cn/thread-276-1-1.html](http://www.tech-q.cn/thread-276-1-1.html)

var  registerForm = new Ext.form.FormPanel    
  ({    
    frame : true,    
    title : '注册新用户',    
    labelSeparator : '：',    
    labelWidth : 150,    
    width : 200,    
    height : 600,    
    waitMsgTarget: true, /*  true的意思是说表单提交时的等待信息在这个表单之内显示，而不是弹出框 \*/   
    items : [    
    {    
        xtype : "textfield",    
        name : 'UserName',    
        id: 'UserName',    
        allowBlank : false,    
        blankText : '注册用户名不能为空',    
        regex : /^\[a-zA-Z]{1}(\[a-zA-Z0-9]|\[.\_]){5,11}$/,    
        regexText : '用户名不合法(必须以字母开头,长度6-12位)!',//验证错误之后的提示信息    
        fieldLabel : '登录名',    
        emptyText : '填写用户名',    
        invalidText : '用户名已经被注册!',    
        width : 250,    
        validationEvent : 'blur',    
        validator : function(thisText) {    
              var res    
              Ext.Ajax.request    
                ({    
                    url : '/portal/Member.do?method=ajaxCheckUserName&UserName='+thisText,    
                    method : 'post',    
                    success : function(response,options)    
                    {    
                  var res = Ext.util.JSON.decode(response.responseText);    
                  if(res.success == true)    
                  {       
                             
                          isok=true;    
                  }    
                  else   
                  {     
                          isok=false;    
                  }    
                   
                  }    
                });    
             
         
            return isok;    
        }    
    },    
    {    
        xtype : "textfield",    
        name : 'PassWord',    
        id : 'PassWord',    
        width : 250,    
        fieldLabel : '输入登录密码',    
        allowBlank : false,    
        inputType : 'password',    
        emptyText : '填写登录密码',    
        blankText : '登录密码不能为空'   
   
    },    
    {    
        xtype : "textfield",    
        name : 'RePassWord',    
        id : 'RePassWord',    
        width : 250,    
        allowBlank : false,    
        fieldLabel : '再次输入密码',    
        emptyText : '填写重复密码',    
        blankText : '重复密码不能为空',    
        vtype : 'password',    
        inputType : 'password',    
        initialPassField : 'PassWord'   
    }, new Ext.form.ComboBox({    
                id : 'Question',    
                name : 'Question',    
                fieldLabel : '请选择密码问题',    
                triggerAction : 'all',    
                editable : false,    
                store : questionstore,    
                emptyText : '请选择',    
                displayField : 'qu',    
                valueField : 'qu',    
                mode : 'local',    
                anchor : '40%',    
                allowBlank : false,    
                blankText : '密码问题不能为空',    
                forceSelection : true,    
                resizable : true,    
                typeAhead : true   
            }),    
   
    {    
        xtype : "textfield",    
        id:  'Answer',    
        name : 'Answer',    
        fieldLabel : '请输入密码问题答案',    
        width : 250,    
        emptyText : '密码问题答案',    
        allowBlank : false,    
        blankText : '密码问题答案不能为空'   
   
    },    
   
    new Ext.form.ComboBox({    
                id : 'RoleType',    
                name : 'RoleType',    
                displayField : 'roleType',    
                fieldLabel : '用户类型',    
                triggerAction : 'all',    
                valueField : 'value',    
                mode: 'local',    
                editable : false,    
                emptyText : '请选择',    
                mode : 'local',    
                anchor : '60%',    
                store : roleTypeStore,    
                allowBlank : false,    
                blankText : '用户类型不能为空',    
                forceSelection : true,    
                resizable : true,    
                typeAhead : true,    
                listeners : {    
                    select : function(form, record, index) {    
                        var store;    
                        getId=record.get('value');    
                        if (record.get('value') == 'f') {    
                            store = familyStore;    
                        } else if (record.get('value') == 'u') {    
                            store = unitStore;    
   
                        } else if (record.get('value') == 'e') {    
                            store = expertStore;    
   
                        } else if (record.get('value') == 'c') {    
                            store = consumerStore;    
   
                        } else if (record.get('value') == 's') {    
                            store = stuffStore;    
   
                        }    
                        registerForm.getForm().findField('AccountType')    
                                .clearValue();    
                        registerForm.getForm().findField('AccountType').store = store;    
   
                        if (registerForm.getForm().findField('AccountType').view) {    
                            registerForm.getForm().findField('AccountType').view    
                                    .setStore(store);    
                        }    
                        registerForm.getForm().findField('AccountType')    
                                .enable();    
   
                    }    
                }    
            }),    
   
    new Ext.form.ComboBox({    
                id : 'AccountType',    
                name : 'AccountType',    
                displayField : 'accountType',    
                valueField : 'value',    
                name : 'AccountType',    
                fieldLabel : '帐户类型',    
                triggerAction : 'all',    
                editable : false,    
                emptyText : '请选择',    
                mode : 'local',    
                anchor : '80%',    
                allowBlank : false,    
                blankText : '密码问题不能为空',    
                forceSelection : true,    
                resizable : true,    
                typeAhead : true   
            }),    
      new Ext.form.TextArea({    
                name : 'Summary',    
                id : 'Summary',    
                fieldLabel : '概述或欢迎辞',    
                width : 300    
            }),    
    {    
        xtype : "textfield",    
        id : 'Email',    
        name : 'Email',    
        fieldLabel : 'E-mail',    
        emptyText : '请输入E-mail(电子邮箱)',    
        allowBlank : false,    
        width : 250,    
        blankText : 'E-mail(电子邮箱)不能为空',    
        regex : /^(\[\\w]+)(.\[\\w]+)\*@(\[\\w-]+\\.){1,5}(\[A-Za-z]){2,4}$/,    
        regexText : '电子邮件格式错误!'//验证错误之后的提示信息    
    }, {    
        xtype : "textfield",    
        id : 'Mobile',    
        name : 'Mobile',    
        fieldLabel : '移动电话',    
        width : 250,    
        regex : /^\[+]{0,1}(\\d){1,3}\[ ]?(\[-]?((\\d)|\[ ]){1,12})+$/,    
        regexText : '移动电话号码格式输入错误!'   
   
    }, {    
        xtype : "textfield",    
        id : 'Telephone',    
        name : 'Telephone',    
        fieldLabel : '电话号码',    
        width : 250,    
        regex : /^\[+]{0,1}(\\d){1,3}\[ ]?(\[-]?((\\d)|\[ ]){1,12})+$/,    
        regexText : '电话号码格式输入错误!'   
    }],    
    buttons : [{    
                text : '注册',    
                handler : registerSubmit    
            }]    
             
     
             
});