New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a clear icon click listener for ClearableTextField #1296
Comments
Hi @bykka ! Is there a reason why you want to distinguish between how the TextField is cleared? |
I use ClearableTextField in my query builder to the database. And of cause, I do not execute a query on every keypress. |
If you want to trigger something when the TextField is empty, this piece of code should work:
|
I do not want to trigger if backspace has been used for clearing. |
You can update the code snippet to:
This will only be triggered if the button is clicked or if backspace is used by selecting 2 or more characters. The snipped can be changed as per the use-case. If you want to only execute when the button is pressed and not on key events, then add a Mouse Event handler and check the length of the TextField inside it:
There are multiple ways to achieve what you are aiming to do. I am not inclined towards making an API change for this requirement. |
Of cause I can find a workaround on how to make it work. It simply looks more natural to have a "clear event" for that.
|
On a second thought, I can think of various usages for this event. Would you be interested in creating a PR? |
I will try it. |
There is no way to distinguish how the text field has been cleared - by pressing backspace or clear icon.
An idea is to add a clean icon click listener to the CustomTextField and method TextFields.createClearableTextField should return this class instead of simple TextField
The text was updated successfully, but these errors were encountered: