PDA

View Full Version : Event for TextField's clear?



Bucs
30 Jan 2011, 1:46 PM
I have a textfield that has it's useClearIcon set to true. If the clear icon is pressed, I would like to run some code, but I can't find any event that I can listen to and run some code upon clear. Am I missing something, any way to do this?

Thx....

MatthieuK
1 Aug 2011, 2:48 AM
Did you find a clean solution? Would be interested as well.

pmarsilio
21 Aug 2011, 4:42 PM
I´ll need to do this too

bob.chesley@nhsoftwerks.com
29 Aug 2011, 8:18 AM
I need to do this also and can't seem to get the behavior I need (i.e., if user backspaces over any search entry I clear filters but if they click clear the search field clears but my list remains filtered).

hoopes
7 Sep 2011, 7:04 PM
After a ton of googling/searching the forum, this appears to be the closest:

http://www.sencha.com/forum/showthread.php?124405-How-to-detect-when-someone-clears-a-textfield

Are there any other avenues? I'm using version 1.1.0. Any help would be amazingly appreciated.

beetree
11 Sep 2011, 5:32 AM
After a ton of googling/searching the forum, this appears to be the closest:

http://www.sencha.com/forum/showthread.php?124405-How-to-detect-when-someone-clears-a-textfield

Are there any other avenues? I'm using version 1.1.0. Any help would be amazingly appreciated.

I tried out that code and didn't get it to work. Have you gotten his override to work properly?

hoopes
11 Sep 2011, 6:05 AM
If you set useClearIcon to true, I believe that override works. I'm using safari to debug during development, and it looks a little funky, but at least my function is getting called.

renato01
1 Nov 2011, 2:02 AM
Luckily they have made this easier in sencha touch 2

If your using new mvc structure, you can use this in the controller init



this.control({
'#yourTextFieldId clearicon': {
tap: function(){console.log('ClearICON tapped');}
}
....
)};

hoopes
1 Nov 2011, 6:26 AM
Thanks for the heads up. I plan to start working with sencha touch 2 this weekend.

cwahlers
7 Dec 2011, 8:01 PM
For the record, it's Ext.form.Text that should be overridden, not Ext.form.TextField

Put this somewhere (might be your index.html, after the sencha js include):


Ext.form.Text.override({
onClearIconTap: function() {
if (!this.disabled) {
this.setValue('');
this.fireEvent('clear', this);
}
}
});

Then listen for the clear event:


listeners: {
clear: function(field) {
// Do something
}
}