<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Java Blog for Alex Wan

    Let life be beautiful like summer flowers and death like autumn leaves.

    統(tǒng)計(jì)

    留言簿(10)

    BlogJava

    Blogs

    DIV+CSS

    JQuery相關(guān)

    友情鏈接

    常去的地方

    數(shù)據(jù)供應(yīng)

    閱讀排行榜

    評(píng)論排行榜

    基于EXT2的RadioGroup

    背景:
    Ext2標(biāo)準(zhǔn)實(shí)現(xiàn)的Radio不夠用!一方面是布局不太方便,另一方面是事件比較難用.所以我實(shí)現(xiàn)了一種以onChange事件為中心的RadioGroup.
    實(shí)現(xiàn)代碼:

      1Ext.namespace('Ext.ux');
      2
      3Ext.ux.Radio =function(config)
      4{
      5    Ext.ux.Radio.superclass.constructor.call(this,config);
      6    this.group = config.group;
      7    this.value=config.value;
      8}
    ;
      9Ext.extend(Ext.ux.Radio ,Ext.form.Radio, {
     10     onRender : function(ct, position){
     11         Ext.ux.Radio.superclass.onRender.call(this, ct, position);
     12          if(this.el && this.el.dom){
     13            this.el.dom.value = this.value;//make the value for radio is the value user has given!
     14        }

     15         this.on('check',this.onCheck);
     16     }
    ,
     17    clearInvalid : function(){
     18         this.group.clearInvalid();
     19    }
    ,markInvalid : function(msg){
     20         this.group.markInvalid(msg);
     21    }
    ,
     22    onClick : function(){
     23        
     24        if(this.el.dom.checked !=this.checked){
     25             this.group.setValue(this.value);
     26        }

     27       
     28    }
    ,
     29     setValue : function(v){
     30        this.checked = (v === true || v === 'true|| v == '1|| String(v).toLowerCase() == 'on');
     31        if(this.el && this.el.dom){
     32            this.el.dom.checked = this.checked;
     33            this.el.dom.defaultChecked = this.checked;
     34            this.group.el.dom.value=this.value;
     35        }

     36    }
    ,onCheck:function(radio,checked)
     37    {
     38        
     39        Ext.log('radiao change!');
     40        if(checked)
     41        {
     42        var oldValue=this.group.getValue();
     43        this.group.onChange(this.group,oldValue,this.getValue());
     44        }

     45        
     46        //this.fireEvent('change', this.group, oldValue, newValue);
     47    }
    ,
     48     getValue : function(){
     49        if(this.rendered){
     50            return this.el.dom.value;
     51        }

     52        return false;
     53    }

     54}
    );
     55
     56Ext.ux.RadioGroup=function(config)
     57{
     58    this.radios=config.radios;
     59    this.defaultValue=config.defaultValue||false;
     60    Ext.ux.RadioGroup.superclass.constructor.call(this,config);    
     61}
    ;
     62Ext.extend(Ext.ux.RadioGroup,Ext.form.Field,  {
     63    defaultAutoCreate:{tag:'input', type:'hidden'},
     64     onRender : function(ct, position){
     65         
     66        Ext.ux.RadioGroup.superclass.onRender.call(this, ct, position);
     67        this.wrap = this.el.wrap({cls: "x-form-check-wrap"});
     68        if (this.radios && this.radios instanceof Array) {
     69            this.els=new Array();
     70            this.els[0]=this.el;
     71            for(var i=0;i<this.radios.length;i++){
     72                var r=this.radios[i];
     73                this.els[i]=new Ext.ux.Radio(Ext.apply({}{
     74                    renderTo:this.wrap,
     75                    hideLabel:true,
     76                    group:this
     77                }
    ,r));
     78                if (this.horizontal) {
     79                    this.els[i].el.up('div.x-form-check-wrap').applyStyles({
     80                        'display': 'inline',
     81                        'padding-left': '5px'
     82                    }
    );
     83                }

     84            }

     85            if(this.hidden)this.hide();
     86        }

     87        this.setDefaultValue();
     88    }
    ,initValue : function(){
     89        //Ext.log('initValue for'+this.name);
     90        if(this.value !== undefined){
     91            this.el.dom.value=this.value;
     92            
     93        }
    else if(this.el.dom.value.length > 0){
     94            this.value=this.el.dom.value;
     95        }

     96    }
    ,getValue:function()
     97    {
     98         if(this.rendered){
     99            return this.el.dom.value;
    100        }

    101        return false;
    102         /*
    103          if(this.value !== undefined){
    104            return this.value;
    105        }else if(this.el.dom.value.length > 0){
    106            return this.el.dom.value;
    107        }
    108        */

    109    }
    ,setValue:function(v)
    110    {
    111        var oldValue=this.getValue();
    112        if(oldValue==v)return ;
    113        for(var j=0;j<this.els.length;j++)
    114            {
    115                if(this.els[j].value==v)
    116                {
    117                    this.els[j].setValue(true);
    118                }

    119                else
    120                {
    121                    this.els[j].setValue(false);
    122                }

    123            }

    124     this.el.dom.value=v;
    125     this.fireEvent('change', this.group, oldValue, v);       
    126    }
    ,
    127    setDefaultValue:function()
    128    {
    129        for(var j=0;j<this.els.length;j++)
    130            {
    131                if(this.els[j].value==this.defaultValue)
    132                {
    133                    this.els[j].setValue(true);
    134                    return;
    135                }

    136                else
    137                {
    138                    if(j<this.els.length-1)
    139                    {
    140                        this.els[j].setValue(false);
    141                    }

    142                    else
    143                    {
    144                        this.els[j].setValue(true);
    145                    }

    146                    
    147                }

    148            }

    149     }
    ,
    150    // private
    151    onDestroy : function(){
    152        if (this.radios && this.radios instanceof Array) {
    153            var cnt = this.radios.length;
    154            for(var x=1;x<cnt;x++){
    155                this.els[x].destroy();
    156            }

    157        }

    158        if(this.wrap){
    159            this.wrap.remove();
    160        }

    161        Ext.ux.RadioGroup.superclass.onDestroy.call(this);
    162    }
    ,
    163    
    164    // private
    165    
    166    onChange : function(oldValue, newValue){
    167        this.fireEvent('change', this, oldValue, newValue);
    168    }

    169
    170}
    );
    171Ext.reg('ux-radiogroup', Ext.ux.RadioGroup);

    例子:
        var boolField= new Ext.ux.RadioGroup({
            fieldLabel : 
    "actionNow",
            allowBlank : 
    true,
            horizontal:
    true,
            maxLength : 
    200,
            defaultValue:'
    true',
            name : 
    "activity.ishavecare",
            radios:[
    {boxLabel:'Yes',value:'true'},{boxLabel:'No',value:'false'}]
            
            
        }
    );
    boolField.on('change',
    function(radioGroup,oldValue,newValue)
    {

    Ext.log('value changes from '
    +oldValue+"  to "+newValue);
    }

    )




    Let life be beautiful like summer flowers and death like autumn leaves.

    posted on 2008-06-09 22:11 Alexwan 閱讀(1947) 評(píng)論(2)  編輯  收藏

    評(píng)論

    # re: 基于EXT2的RadioGroup 2009-08-11 21:00 盛樹(shù)

    垃圾的東西~~
    看看這個(gè)吧!~~


    var checkTimeType = {"check": function(radioGroup, checked) {
    if (checked)
    alert(radioGroup.name + " radio (value=" + radioGroup.inputValue + ") had change "+checked);
    }};
    var ssTimeType = { xtype: 'radiogroup',
    fieldLabel: '時(shí)間類(lèi)型',
    itemCls: 'x-check-group-alt',
    columns: 2,
    items: [{boxLabel: '不定時(shí)間', name: 'ssTimeType', inputValue: 0, listeners: checkTimeType},
    {boxLabel: '具體時(shí)間', name: 'ssTimeType', inputValue: 1, listeners: checkTimeType, checked: true}]};  回復(fù)  更多評(píng)論   

    # re: 基于EXT2的RadioGroup 2009-08-12 09:21 Alexwan

    樓上的請(qǐng)看清了我文章的發(fā)表時(shí)間,你提到的'x-check-group-alt'組件是在我寫(xiě)這個(gè)組件之后的幾個(gè)月才出現(xiàn)的,而且介于當(dāng)時(shí)個(gè)人能力的有限,寫(xiě)出來(lái)的組件有局限很正常;在評(píng)論別人或者別人的作品時(shí),請(qǐng)考察清楚。  回復(fù)  更多評(píng)論   


    只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 美女被cao网站免费看在线看| 3344永久在线观看视频免费首页| 国产亚洲视频在线| 老子影院午夜伦不卡亚洲| 国产精品福利片免费看| 久久不见久久见免费视频7| 免费观看的av毛片的网站| 亚洲国产成人乱码精品女人久久久不卡| 国产成人在线观看免费网站| 亚洲国产精彩中文乱码AV| 中文字幕 亚洲 有码 在线| 五月天国产成人AV免费观看| 亚洲视频免费在线看| 免费成人av电影| 亚洲免费在线观看视频| 两个人看的www免费高清| 久久精品国产免费观看三人同眠| 国产中文字幕免费观看| 亚洲午夜在线电影| 色吊丝免费观看网站| 日韩欧毛片免费视频| 亚洲AV无码日韩AV无码导航| 亚洲AV日韩综合一区| 24小时日本在线www免费的| 亚洲网站在线观看| av电影在线免费看| 免费A级毛片在线播放不收费| 亚洲乱码日产精品BD在线观看| 日本道免费精品一区二区| 亚洲综合伊人久久大杳蕉| 免费一级特黄特色大片| 国产一区二区三区免费看| 亚洲av无码专区亚洲av不卡| 一二三四在线播放免费观看中文版视频 | 亚洲嫩草影院久久精品| eeuss影院免费直达入口| 亚洲精品无码久久久| 色婷婷精品免费视频| 亚洲情综合五月天| 99热这里只有精品6免费| 亚洲视屏在线观看|