primolan
12 Apr 2010, 11:19 AM
Hello!
I saw a lot of people asking about a field with a button by its side. I actually followed the idea from fileuploadfield and I did some code here.
It works fine with TextField but it fails at onResize method with Trigger fields. I really don't know why! Please, help me! Thanks in advance!
Here is the code:
Ext.form.Field.prototype.onRender = Ext.form.Field.prototype.onRender.createSequence(function(thisContainer, thisPosition){
if (this.buttonConfig) {
this.wrap = this.el.wrap({
style: 'clear: both;'
});
this.el.applyStyles('float: left;');
this.button = new Ext.Button(Ext.apply(this.buttonConfig, {
renderTo: this.wrap,
style: 'float: right;'
}));
}
});
Ext.form.Field.prototype.onResize = Ext.form.Field.prototype.onResize.createSequence(function(adjWidth, adjHeight, rawWidth, rawHeight){
if (this.buttonConfig) {
this.wrap.setSize(adjWidth, adjHeight);
var elWidth = this.wrap.getWidth() - this.button.getEl().getWidth() - (this.defaultTriggerWidth ? this.defaultTriggerWidth : 0) - this.buttonConfig.buttonOffset;
this.el.setSize(elWidth, adjHeight);
}
});
//var field = new Ext.form.TextField({
var field = new Ext.form.ComboBox({
renderTo: Ext.getBody(),
buttonConfig: {
buttonOffset: 3,
iconCls: 'icon-add',
handler: function(thisButton) {
alert('button handler');
}
},
store: ['Rodrigo', 'Primolan'],
width: 300
});
I saw a lot of people asking about a field with a button by its side. I actually followed the idea from fileuploadfield and I did some code here.
It works fine with TextField but it fails at onResize method with Trigger fields. I really don't know why! Please, help me! Thanks in advance!
Here is the code:
Ext.form.Field.prototype.onRender = Ext.form.Field.prototype.onRender.createSequence(function(thisContainer, thisPosition){
if (this.buttonConfig) {
this.wrap = this.el.wrap({
style: 'clear: both;'
});
this.el.applyStyles('float: left;');
this.button = new Ext.Button(Ext.apply(this.buttonConfig, {
renderTo: this.wrap,
style: 'float: right;'
}));
}
});
Ext.form.Field.prototype.onResize = Ext.form.Field.prototype.onResize.createSequence(function(adjWidth, adjHeight, rawWidth, rawHeight){
if (this.buttonConfig) {
this.wrap.setSize(adjWidth, adjHeight);
var elWidth = this.wrap.getWidth() - this.button.getEl().getWidth() - (this.defaultTriggerWidth ? this.defaultTriggerWidth : 0) - this.buttonConfig.buttonOffset;
this.el.setSize(elWidth, adjHeight);
}
});
//var field = new Ext.form.TextField({
var field = new Ext.form.ComboBox({
renderTo: Ext.getBody(),
buttonConfig: {
buttonOffset: 3,
iconCls: 'icon-add',
handler: function(thisButton) {
alert('button handler');
}
},
store: ['Rodrigo', 'Primolan'],
width: 300
});