[EXT Develop Log]--comboBox?radio?Fix it!

Did u feel some problem when u use the ext.form.comboBox or radio?

 


 

1.Yes,when u use the comboBox and submit the form to ur service, maybe u will wonder why the parameter posted is the selected value and not the option value,and u had set the "valueField" already...

See the definition of comboBox:

"hiddenName: This is an autocreated hidden field that gets the value of what ever you select"

so ,remember option "valueField" must work with "hiddenName" in comboBox~~o(∩_∩)o...


2.When u select one record in data(grid .etc),and load this record to a form, and used setValues to conver the form.what happen?every element can get the data well but, except radio,u can not get the radio to populate  from the data when this form load.
resolve this ,override the setValues method of radio, add follow code in ur js:

js 代码
 
  1. Ext.form.BasicForm.prototype.setValues = function(values){   
  2.     if(values instanceof Array){                
  3.         for(var i = 0, len = values.length; i < len; i++){   
  4.             var v = values[i];   
  5.             var f = this.findField(v.id);   
  6.             if(f){   
  7.                 if ( f.getEl().dom.type == 'radio' ) {   
  8.                     var group = this.el.dom.elements[f.getName()];   
  9.                     for (var i=0; i < group.length; i++ ) {   
  10.                         if(group[i].__ext_field) {   
  11.                             group[i].__ext_field.setValue(group[i].value == v);   
  12.                             if(this.trackResetOnLoad){   
  13.                                 group[i].__ext_field.originalValue = group[i].__ext_field.getValue();   
  14.                             }   
  15.                         }   
  16.                     }   
  17.                 }   
  18.                 else  
  19.                 {   
  20.                     f.setValue(v.value);   
  21.                     if(this.trackResetOnLoad){   
  22.                         f.originalValue = f.getValue();   
  23.                     }   
  24.                 }   
  25.             }   
  26.         }   
  27.     }else{   
  28.         var field, id;   
  29.         for(id in values){   
  30.             if(typeof values[id] != 'function' && (field = this.findField(id))){   
  31.                 if( field.getEl().dom.type == 'radio' ) {   
  32.                     var group = this.el.dom.elements[field.getName()];   
  33.                     for (var i=0; i < group.length; i++ ) {   
  34.                         if(group[i].__ext_field) {   
  35.                             group[i].__ext_field.setValue(group[i].value == values[id]);   
  36.                             if(this.trackResetOnLoad){   
  37.                                 group[i].__ext_field.originalValue = group[i].__ext_field.getValue();   
  38.                             }   
  39.                         }   
  40.                     }   
  41.                 }   
  42.                 else  
  43.                 {   
  44.                     field.setValue(values[id]);   
  45.                     if(this.trackResetOnLoad){   
  46.                         field.originalValue = field.getValue();   
  47.                     }   
  48.                 }   
  49.             }   
  50.         }   
  51.     }   
  52.     return this;   
  53. }   
  54.   
  55.   
  56.   
  57. Ext.form.Radio.prototype.onRender = function(ct, position) {   
  58.   Ext.form.Radio.superclass.onRender.call(this, ct, position);   
  59.   this.el.dom.__ext_field = this;   
  60. }   
  61.   
  62. Ext.form.Radio.prototype.setValue = function(v) {   
  63.     if(v === true || v === 'true' || v == '1' || v === false || v === 'false' || v == '0') {   
  64.   
  65.         // Select all radios of this group   
  66.         var radios = this.el.up('form').select('input[type=radio]');   
  67.   
  68.         // Uncheck all other values   
  69.         for(var i = 0; i < radios.elements.length; i++) {   
  70.             if(radios.elements[i].__ext_field && radios.elements[i].__ext_field != this && radios.elements[i].name == this.el.dom.name)   
  71.             {   
  72.                 radios.elements[i].__ext_field.checked = false;   
  73.                    
  74.                 // DOM checked is set by the browser   
  75.   
  76.                 radios.elements[i].__ext_field.fireEvent("check"thisthis.checked);   
  77.             }   
  78.         }   
  79.            
  80.         this.checked = (v === true || v === 'true' || v == '1');   
  81.         if(this.el && this.el.dom) {   
  82.             this.el.dom.checked = this.checked;   
  83.         }   
  84.         this.fireEvent("check"thisthis.checked);   
  85.     }   
  86. }  

你可能感兴趣的:(prototype,ext,F#,UP)