Extjs中常用表單介紹與應(yīng)用
知道表單面板如何創(chuàng)建
了解表單面板中xtype的類型的應(yīng)用
知道表單面板如何驗證,綁定,取值
綜合應(yīng)用表單面板(玩轉(zhuǎn)它)
內(nèi)容:
首先我們要理解的是FormPanel也是繼承panel組件的。所以它有著panel的屬性
要創(chuàng)建一個表單面板其實很簡單 var MyformPanel=new Ext.form.formpanel();
表單面板和面板一樣只是作為一個容器出現(xiàn)的,需要我們使用items加入各控件元素來豐富我們的表單面板,
defaults:{},此屬性提取了items中各組件項的共同屬性
對于xtype:在表單面板中非常有用,沒有必要每次都用new 來創(chuàng)建一個組件,它定義了組件的類型,同時讓組件在加載后渲染。
form Ext.FormPanel
checkbox Ext.form.Checkbox
combo Ext.form.ComboBox
datefield Ext.form.DateField
field Ext.form.Field
fieldset Ext.form.FieldSet
hidden Ext.form.Hidden
htmleditor Ext.form.HtmlEditor
label Ext.form.Label
numberfield Ext.form.NumberField
radio Ext.form.Radio
textarea Ext.form.TextArea
textfield Ext.form.TextField
timefield Ext.form.TimeField
trigger Ext.form.TriggerField
對于表單驗證,Extjs提供了非常強大的支持,在后面的實例中大家可以發(fā)現(xiàn)
實例分析講解:
一,創(chuàng)建表單面板
function Read2() {
Ext.QuickTips.init();
var MyForm=new Ext.form.FormPanel({
title:'表單應(yīng)用',
width:300,
x:300,
y:50,
floating:true,
tools:[{id:'close'}],
frame:true,
bodyStyle:'padding:10px 0px 1px 1px',
labelSeparator:':',
labelAlign:'right',
renderTo:Ext.getBody(),//為什么這里不可以用'id1'
defaults:{xtype:'textfield',width:150,allowBlank:false,msgTarget:'side'},//提取共同屬性
items:[
{
fieldLabel:'用戶名稱',
name:'username',
id:'user',
emptyText:'請輸入用戶名',
blankText:'請輸入用戶名'
},
{
fieldLabel:'用戶密碼',
name:'userpassword',
id:'password',
inputType:'password',//它還包括 radiocheck text(默認(rèn)) filepassword等等
blankText:'請輸入密碼'
}
],
buttons:[{text:"確定"},{text:"取消",handler:function(){alert("事件!");}}],
buttonAlign:'center'
});
}
注意:renderTo:'id1' 這個時候表單面板顯示失效 想來很久不知道是怎么一回事
二,基本表單組建的應(yīng)用于說明 (通常情況下我們都是利用xtype來說明 items中組件的類型)
fieldset的應(yīng)用
function Read3() {
var MyformPanel=new Ext.form.FormPanel({
title:'fieldset的應(yīng)用',
renderTo:Ext.getBody(),
frame:true,
width:350,
x:400,
y:50,
floating:true,
items:[
{
xtype:'fieldset',
title:'用戶信息',
collapsible:true,
autoHeight:true,
autoWidth:true,
defaults:{width:150,allowBlank:false,xtype:'textfield'},
items:[
{
fieldLabel:'用戶名稱',
emptyText:'陳建強',
blankText:'請輸入用戶名稱'
},
{
fieldLabel:'用戶密碼',
inputType:'password',
blankText:'請輸入用戶密碼'
}
]
}
]
});
}

表單面板中基本組件的介紹
function Read3() {
2 Ext.QuickTips.init();//初始化tips
3 Ext.apply(Ext.form.VTypes,{
4 password:function(val,field){//val指這里的文本框值,field指這個文本框組件,大家要明白這個意思
5 if(field.confirmTo){//confirmTo是我們自定義的配置參數(shù),一般用來保存另外的組件的id值
6 var pwd=Ext.get(field.confirmTo);//取得confirmTo的那個id的值
7 return (val==pwd.getValue());
8 }
9 return true;
}
});
var MyformPanel=new Ext.form.FormPanel({
title:'fieldset的應(yīng)用',
renderTo:Ext.getBody(),
frame:true,
width:550,
x:400,
y:50,
draggable:{
insertProxy: false,//拖動時不虛線顯示原始位置
onDrag : function(e){
var pel = this.proxy.getEl();
this.x = pel.getLeft(true);
this.y = pel.getTop(true);//獲取拖動時panel的坐標(biāo)
var s = this.panel.getEl().shadow;
if (s){
s.realign(this.x, this.y, pel.getWidth(), pel.getHeight());
}
},
endDrag : function(e){
this.panel.setPosition(this.x, this.y);//移動到最終位置
}
},
plain:true,
floating:true,
items:[
{
xtype:'fieldset',
checkboxToggle:true,
checkboxName:'user',
title:'用戶信息',
collapsible:true,
autoHeight:true,
autoWidth:true,
labelSeparator:':',
labelAlign:'right',
labelWidth:70,
defaults:{width:150,allowBlank:false,xtype:'textfield'},
items:[
{
fieldLabel:'用戶名稱',
emptyText:'陳建強',
id:'user',
name:'userName',
blankText:'請輸入用戶名稱',
anchor:'95%'
},
{
fieldLabel:'用戶密碼',
inputType:'password',// password text checkbox rodio
id:'password',
name:'userpassword',
value:'0717',
blankText:'請輸入用戶密碼',
anchor:'95%'
},
{
fieldLabel:'確認(rèn)密碼',
id:'password2',
name:'userpassword2',
inputType:'password',
vtype:'password',
vtypeText:'兩次輸入的密碼不一致',
confirmTo:'userpassword',
anchor:'95%'
},
{
xtype:"datefield",
fieldLabel:"出生日期",
anchor:"95%"
},
{
fieldLabel:'我的博客',
value:'http://www.cnblogs.com/chenjq0717',
vtype:'url',
vtypeText:'不是有效的url',
id1:'myblog',
name:'myblog',
anchor:'95%'
},
{
//alpha 只能輸入字母,無法輸入其他(如數(shù)字,特殊符號等)
//2.alphanum//只能輸入字母和數(shù)字,無法輸入其他
//3.email//email驗證,要求的格式是"langsin@gmail.com"
//4.url//url格式驗證,要求的格式是http://www.langsin.com
fieldLabel:'電子郵箱',
vtype:'email',
vtypeText:'不是有效的郵箱',
name:'email',
anchor:'95%'
},
{
xtype:"panel",
layout:"column",
fieldLabel:'性別',
isFormField:true,
items:[{
columnWidth:.5,
xtype:"radio",
boxLabel:"男",
name:"sex"
//inputValue
},{
columnWidth:.5,
checked:true,
xtype:"radio",
boxLabel:"女",
name:"sex"
}]
},
{
xtype:"panel",
layout:"column",//也可以是table,實現(xiàn)多列布局
fieldLabel:'愛好',
isFormField:true,//非常重要,否則panel默認(rèn)不顯示fieldLabel
items:[{
columnWidth:.5,//寬度為50%
xtype:"checkbox",
boxLabel:"足球",//顯示在復(fù)選框右邊的文字
name:""
},{
columnWidth:.5,
xtype:"checkbox",
boxLabel:"籃球",
name:""
}]
},
{
xtype:'combo',
fieldLabel:'用戶家鄉(xiāng)',
name:'family',
store:<%=getfamilyData() %>,//調(diào)用后臺變量
emptyText:'請選擇家鄉(xiāng)'
},
{
xtype:"htmleditor",
id:"myinfo",
fieldLabel:"個人說明",
anchor:"99%"
}
]
}
]
});
}

表單數(shù)據(jù)提交到服務(wù)器 submit
submit: function(){
this.getEl().dom.action = 'MyPages/GetForm.aspx', //提交后轉(zhuǎn)向的頁面
this.getEl().dom.method='POST',//提交方式
this.getEl().dom.submit();//執(zhí)行提交
},
添加提交按鈕
buttons:[{text:"確定",handler:login,formBind:true},{text:"取消",handler:reset}]
添加提交方法:
function login(){
MyformPanel.form.submit();//提交
}
function reset(){
MyformPanel.form.reset();//取消
}

本課代碼:
表單面板的綜合應(yīng)用
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Ext7.aspx.cs" Inherits="EXT1.Ext7" %>
2
3 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4
5 <html xmlns="http://www.w3.org/1999/xhtml" >
6 <head runat="server">
7 <title>第七課,Extjs中常用表單介紹與應(yīng)用</title>
8 <link href="ext-3.2.0/resources/css/ext-all.css" rel="stylesheet" type="text/css" />
9 <script src="ext-3.2.0/adapter/ext/ext-base.js" type="text/javascript"></script>
<script src="ext-3.2.0/ext-all.js" type="text/javascript"></script>
<script type="text/javascript">
function Read1() {
Ext.QuickTips.init();
var MyForm=new Ext.form.FormPanel({
title:'表單應(yīng)用',
width:300,
height:200,
x:300,
y:50,
floating:true,
tools:[{id:'close'}],
draggable:{
insertProxy: false,//拖動時不虛線顯示原始位置
onDrag : function(e){
var pel = this.proxy.getEl();
this.x = pel.getLeft(true);
this.y = pel.getTop(true);//獲取拖動時panel的坐標(biāo)
var s = this.panel.getEl().shadow;
if (s){
s.realign(this.x, this.y, pel.getWidth(), pel.getHeight());
}
},
endDrag : function(e){
this.panel.setPosition(this.x, this.y);//移動到最終位置
}
},
frame:true,
labelSeparator:':',
labelAlign:'right',
renderTo:Ext.getBody(),//為什么這里不可以用'id1'
items:[
new Ext.form.TextField({
fieldLabel:'用戶名稱',
allowBlank:false,
blankText:'請輸入用戶名',
msgTarget:'side'
}),
new Ext.form.TextField({
fieldLabel:'用戶密碼',
allowBlank:false,
inputType:'password',
blankText:'請輸入密碼',
msgTarget:'side'
})
]
});
}
function Read2() {
Ext.QuickTips.init();
var MyForm=new Ext.form.FormPanel({
title:'表單應(yīng)用',
width:300,
x:300,
y:50,
floating:true,
tools:[{id:'close'}],
frame:true,
bodyStyle:'padding:10px 0px 1px 1px',
labelSeparator:':',
labelAlign:'right',
draggable:{
insertProxy: false,//拖動時不虛線顯示原始位置
onDrag : function(e){
var pel = this.proxy.getEl();
this.x = pel.getLeft(true);
this.y = pel.getTop(true);//獲取拖動時panel的坐標(biāo)
var s = this.panel.getEl().shadow;
if (s){
s.realign(this.x, this.y, pel.getWidth(), pel.getHeight());
}
},
endDrag : function(e){
this.panel.setPosition(this.x, this.y);//移動到最終位置
}
},
renderTo:Ext.getBody(),//為什么這里不可以用'id1'
defaults:{xtype:'textfield',width:150,allowBlank:false,msgTarget:'side'},//提取共同屬性
items:[
{
fieldLabel:'用戶名稱',
name:'username',
id:'user',
emptyText:'請輸入用戶名',
blankText:'請輸入用戶名'
},
{
fieldLabel:'用戶密碼',
name:'userpassword',
id:'password',
inputType:'password',
blankText:'請輸入密碼'
}
],
buttons:[{text:"確定"},{text:"取消",handler:function(){alert("事件!");}}],
buttonAlign:'center'
});
}
function Read3() {
Ext.QuickTips.init();//初始化tips
Ext.apply(Ext.form.VTypes,{
password:function(val,field){//val指這里的文本框值,field指這個文本框組件,大家要明白這個意思
if(field.confirmTo){//confirmTo是我們自定義的配置參數(shù),一般用來保存另外的組件的id值
var pwd=Ext.get(field.confirmTo);//取得confirmTo的那個id的值
return (val==pwd.getValue());
}
return true;
}
});
var MyformPanel=new Ext.form.FormPanel({
title:'fieldset的應(yīng)用',
renderTo:Ext.getBody(),
frame:true,
width:550,
x:400,
y:50,
draggable:{
insertProxy: false,//拖動時不虛線顯示原始位置
onDrag : function(e){
var pel = this.proxy.getEl();
this.x = pel.getLeft(true);
this.y = pel.getTop(true);//獲取拖動時panel的坐標(biāo)
var s = this.panel.getEl().shadow;
if (s){
s.realign(this.x, this.y, pel.getWidth(), pel.getHeight());
}
},
endDrag : function(e){
this.panel.setPosition(this.x, this.y);//移動到最終位置
}
},
submit: function(){
this.getEl().dom.action = 'MyPages/GetForm.aspx',
this.getEl().dom.method='POST',
this.getEl().dom.submit();
},
plain:true,
floating:true,
items:[
{
xtype:'fieldset',
checkboxToggle:true,
checkboxName:'user',
title:'用戶信息',
collapsible:true,
autoHeight:true,
autoWidth:true,
labelSeparator:':',
labelAlign:'right',
labelWidth:70,
defaults:{width:150,allowBlank:false,xtype:'textfield'},
items:[
{
fieldLabel:'用戶名稱',
//emptyText:'陳建強',
id:'user',
name:'userName',
blankText:'請輸入用戶名稱',
anchor:'95%'
},
{
fieldLabel:'用戶密碼',
inputType:'password',// password text checkbox rodio
id:'password',
name:'userpassword',
value:'0717',
blankText:'請輸入用戶密碼',
anchor:'95%'
},
{
fieldLabel:'確認(rèn)密碼',
id:'password2',
name:'userpassword2',
inputType:'password',
vtype:'password',
vtypeText:'兩次輸入的密碼不一致',
confirmTo:'userpassword',
anchor:'95%'
},
{
xtype:"datefield",
fieldLabel:"出生日期",
anchor:"95%"
},
{
fieldLabel:'我的博客',
value:'http://www.cnblogs.com/chenjq0717',
vtype:'url',
vtypeText:'不是有效的url',
id1:'myblog',
name:'myblog',
anchor:'95%'
},
{
//alpha 只能輸入字母,無法輸入其他(如數(shù)字,特殊符號等)
//2.alphanum//只能輸入字母和數(shù)字,無法輸入其他
//3.email//email驗證,要求的格式是"langsin@gmail.com"
//4.url//url格式驗證,要求的格式是http://www.langsin.com
fieldLabel:'電子郵箱',
vtype:'email',
vtypeText:'不是有效的郵箱',
name:'email',
anchor:'95%'
},
{
xtype:"panel",
layout:"column",
fieldLabel:'性別',
isFormField:true,
items:[{
columnWidth:.5,
xtype:"radio",
boxLabel:"男",
name:"sex"
//inputValue
},{
columnWidth:.5,
checked:true,
xtype:"radio",
boxLabel:"女",
name:"sex"
}]
},
{
xtype:"panel",
layout:"column",//也可以是table,實現(xiàn)多列布局
fieldLabel:'愛好',
isFormField:true,//非常重要,否則panel默認(rèn)不顯示fieldLabel
items:[{
columnWidth:.5,//寬度為50%
xtype:"checkbox",
boxLabel:"足球",//顯示在復(fù)選框右邊的文字
name:""
},{
columnWidth:.5,
xtype:"checkbox",
boxLabel:"籃球",
name:""
}]
},
{
xtype:'combo',
fieldLabel:'用戶家鄉(xiāng)',
name:'family',
store:<%=getfamilyData() %>,//調(diào)用后臺變量
emptyText:'請選擇家鄉(xiāng)'
},
{
xtype:"htmleditor",
id:"myinfo",
fieldLabel:"個人說明",
anchor:"99%"
}
]
}
],
buttons:[{text:"確定",handler:login,formBind:true},{text:"取消",handler:reset}]
});
function login(){
MyformPanel.form.submit();//提交
}
function reset(){
MyformPanel.form.reset();//取消
}
}
Ext.onReady(Read3);
</script>
</head>
<body>
<form id="form1" runat="server">
<div id="id1">
</div>
</form>
</body>
<script type="text/javascript">
</script>
</html>
- extjs圖表繪制之條形圖實現(xiàn)方法分析
- extjs4圖表繪制之折線圖實現(xiàn)方法分析
- Extjs grid添加一個圖片狀態(tài)或者按鈕的方法
- ExtJS[Desktop]實現(xiàn)圖標(biāo)換行示例代碼
- 解決Extjs上傳圖片無法預(yù)覽的解決方法
- ExtJs之帶圖片的下拉列表框插件
- ExtJs使用總結(jié)(非常詳細(xì))
- 學(xué)習(xí)ExtJS Window常用方法
- Extjs學(xué)習(xí)筆記之五 一個小細(xì)節(jié)renderTo和applyTo的區(qū)別
- ExtJS 簡介 讓你知道extjs是什么
- ExtJS下grid的一些屬性說明
- extjs圖形繪制之餅圖實現(xiàn)方法分析
相關(guān)文章
Extjs中的GridPanel隱藏列會顯示在menuDisabled中解決方法
在Extjs中的GridPanel會有這樣的情況,隱藏列會顯示在menuDisabled中,但是這個一般沒有什么用處,只是用于后臺取值的作用,感興趣的朋友可以了解下啊,希望本文對你有所幫助2013-01-01ExtJs設(shè)置GridPanel表格文本垂直居中示例
本文為大家詳細(xì)介紹下ExtJs如何設(shè)置GridPanel表格文本垂直居中,具體實現(xiàn)代碼及截圖如下,感興趣的朋友可以參考下哈,希望對大家有所幫助2013-07-07Extjs中ComboBoxTree實現(xiàn)的下拉框樹效果(自寫)
最近涉及到的一個項目中,需要實現(xiàn)ComboBoxTree的效果,由于在Extjs中是沒有這種效果,所以看看別人的資料自己寫了一個,感興趣的朋友可以參考下哈2013-05-05ExtJs 學(xué)習(xí)筆記 Ext.Panle Ext.TabPanel Ext.Viewport
ExtJs 學(xué)習(xí)筆記基礎(chǔ)篇 面板的使用(Ext.Panle、Ext.TabPanel、Ext.Viewport)2008-12-12ExtJs3.0中Store添加 baseParams 的Bug
今天發(fā)現(xiàn)了一個ExtJS3.0中的Bug 以前用2.0的時候,喜歡這樣增加參數(shù)2010-03-03基于ExtJs在頁面上window再調(diào)用Window的事件處理方法
下面小編就為大家?guī)硪黄贓xtJs在頁面上window再調(diào)用Window的事件處理方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-07-07