对Ext中CheckBox的扩展
?
使用Ext中的Checkbox时,经常需要随form一起提交,但Checkbox设置的默认的提交值为"on"或"",后台代码中需要对字段的提交进行判断后取值,不符合我们通常的使用习惯,即直接将提交的值转换为对应的boolean类型,为此,特进行扩展和封装,以满足通过的使用方式,代码如下:
?
justgin.bap.CheckboxEx = Ext.extend(Ext.form.Checkbox, {trueValue: true,falseValue: false,hiddenField: {value:''},onRender : function(ct, position){ justgin.bap.CheckboxEx.superclass.onRender.call(this, ct, position); var hidden = this.el.insertSibling({tag:'input', type:'hidden', name: this.name}, 'before', true); hidden.value = this.hiddenField.value; this.hiddenField = hidden; this.el.dom.removeAttribute('name'); this.on('check', this.onCheck); }, setValue : function(v){ var me = this; justgin.bap.CheckboxEx.superclass.setValue.call(this, v); this.hiddenField.value = this.checked?me.trueValue:me.falseValue; }, getValue : function(v){ return this.hiddenField.value; }, onDestroy : function(){ Ext.destroy(this.wrap); justgin.bap.CheckboxEx.superclass.onDestroy.call(this); },onCheck : function(me, checked){ this.hiddenField.value = checked?me.trueValue:me.falseValue; }});?
Ext.reg('checkbox', justgin.bap.CheckboxEx);?