ziesemer
11 Oct 2007, 12:01 PM
I was attempting to use a "Clearable" TriggerField in 1.1.1, very much just like the example at the top of the TriggerField doc page.
var clearableField = new Ext.form.TriggerField({
triggerClass: "x-form-trigger x-form-clear-trigger",
emptyText: "Field Description",
value: ""
});
clearableField.onTriggerClick = function(){
this.reset();
};
clearableField.applyTo("someTextField");
This mostly works as expected. However, if typing something in the field, then clicking the trigger, then clicking back in the field to type something else, the "Field Description" (emptyText) doesn't remove itself as expected. (Clicking then typing "test" results in "Field Descriptiontest" being displayed in the field.)
The problem seems to be that the "focus" event never fires, so the emptyText is never removed. (The TriggerField is already focused, but internally, the focus is moving from the trigger button to the underlying field.)
Here's the work-around I'm currently using: (Placed after the above .applyTo(...), where I'm guessing it needs to be.)
clearableField.getEl().addListener("focus", function(){
if(!clearableField.getValue()){
clearableField.setRawValue(); /* same as .setRawValue(null) or .setRawValue("") */
}
});
var clearableField = new Ext.form.TriggerField({
triggerClass: "x-form-trigger x-form-clear-trigger",
emptyText: "Field Description",
value: ""
});
clearableField.onTriggerClick = function(){
this.reset();
};
clearableField.applyTo("someTextField");
This mostly works as expected. However, if typing something in the field, then clicking the trigger, then clicking back in the field to type something else, the "Field Description" (emptyText) doesn't remove itself as expected. (Clicking then typing "test" results in "Field Descriptiontest" being displayed in the field.)
The problem seems to be that the "focus" event never fires, so the emptyText is never removed. (The TriggerField is already focused, but internally, the focus is moving from the trigger button to the underlying field.)
Here's the work-around I'm currently using: (Placed after the above .applyTo(...), where I'm guessing it needs to be.)
clearableField.getEl().addListener("focus", function(){
if(!clearableField.getValue()){
clearableField.setRawValue(); /* same as .setRawValue(null) or .setRawValue("") */
}
});