ExtJs學習(二)(表單)

來源:互聯網
上載者:User

標籤:des   style   http   java   color   使用   

Ext.onReady(function{
  var jj_form = new Ext.FormPanel({
  url : ‘jj_form_submit.java‘,
  renderTo : document.body,
  frame : true,
  title : ‘formtest_jj‘,
  width : 250,
  items : [{
    xtype : ‘textfield‘,
    fieldlabel : ‘username‘,
    name : ‘username‘
},{
    xtype : ‘textfield‘,
    fieldlabel : ‘password‘,
    name " ‘password‘
},{
    xtype : ‘datafield‘,
    fieldlabel : ‘data‘,
    name : data
}    
]
});
});

這個實際上就是一個表單對象,其中xtype表示的是表單控制項的類型,類型有:textfield,timefield,datafield,numberfield,combo,textarea.

表單校正功能:

  allowBlank : false ;不允許空。
  disabledDays : [1,2,3,4,5] 不允許選擇星期一,二,三,四,五。一定要記得0代表Sunday
  其實vtype這種內建校正也是可以進行檢驗的,比如:vtype : ‘alpha‘ 則表示輸入只能匹配文字字元,還有許多其他的約束條件,可以通過論壇中尋找擷取到。

顯示錯誤的方式:  
  Ext.onReady(function(){
  Ext.QuickTips.init() //通常是放在第一行,通過一個氣球來提示錯誤資訊
  });

自訂檢驗,設定自己的vtype:
  Ext.form.VTypes[‘nameVal‘] = /^[A-Z][A-Za-z\-] + [A-Z][A-Za-z\-] + $/;
  Ext.form.VTypes[‘nameMask‘] = /[A-Za-z\-]/;
  Ext.form.VTypes[‘nameText‘] = ‘Invalid name!‘;
  Ext.form..VTypes[‘name‘] = function(v){
    return Ext.form.VTypes[‘nameVal‘].test(v);
}

選項按鈕(radio button),複選框(check boxes)和組合框(ComboBox)

radio button : {
  xtype : ‘radio‘,
  fieldlabel : ‘Color‘.
  name : ‘color‘,
  boxlabel : ‘White‘
}.{
  xtype : ‘radio‘,
  name : ‘color‘,
  hideLabel : false,
  boxlabel : ‘Black‘
  labelSpearator : ‘‘
}

check box : {
  xtype : ‘checkbox‘,
  fieldlabel : ‘Are you sure‘,
  name : ‘Are you sure‘
}

comboBox :
首先要定義一個資料集合,其中data可以有很多種的形式,這裡我們選擇的是SimpleStore。

var data_store = new Ext.data.SimpleStore(){
  fields : [‘id‘, ‘username‘],
  name : [[1, aichengqi], [2, chenli],[3, yuguoxin]]
})
{
  xtype : ‘combo‘,
  fieldlabel : ‘user‘,
  name : ‘user‘,
  mode : ‘local‘,
  store : ‘username‘,
  displayfield : ‘username‘,
  width : 120
}

資料庫驅動的ComboBox

這裡是用PHP語言編寫的如何擷取JSON資料的方式;(由於涉及到了PHP的函數問題,就沒有過多研究了)

之後我們使用JSON Reader來實現遠端資料的功能;

var remote_data = new Ext.data.Store({
  reader : new Ext.data.JsonReader({
    fields : [id, username],
    root : ‘rows‘
}),
  proxy : new Ext.data.HttpProxy({
    url : data/username.php
}),
  autoLoad : true
}
);
remote_data.load();

文本域(TextArea)和html編輯器(html Editor)

TextArea :
{
  xtype : ‘textarea‘,
  fieldlabel : ‘comment‘,
  name : ‘commment‘,
  labelSeparator : ‘‘,
  hideLabel : true,
  height : 100,
  anchor : ‘100%‘
}

html Dditor 和上面的一樣 :
{
  xtype : ‘htmleditor‘,
  fieldlabel : ‘editor‘,
  name : ‘editor‘,
  hideLabel : true,
  labelSeparator,
  height : 100,
  anchor : ‘100%‘
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.