Skip to content
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

feat(android): new event for empty TextFields #13975

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft

Conversation

m1ga
Copy link
Contributor

@m1ga m1ga commented Jan 26, 2024

The change event on a TextField is only called when there is content in the field. If it is empty and you press "backspace" again you won't get any event.

I've added an event: emptyField that will fire.

const win = Ti.UI.createWindow({});
var tf1 = Ti.UI.createTextField({
	width: 150,
	left: 10
});
var tf2 = Ti.UI.createTextField({
	width: 150,
	right: 10,
	value: "remove me"
});
tf2.addEventListener("emptyField", function(e) {
	console.log("key", e.keyCode)
	tf1.focus();
})
tf2.addEventListener("change", function(e) {
	console.log("change", tf2.value.length)
})
win.add(tf1);
win.add(tf2);
win.addEventListener("open", function() {
	tf2.focus();
})
win.open();
simplescreenrecorder-2024-01-26_23.01.21.mp4

TODO:

  • Docs
  • rename it?
  • someone needs to check if iOS has something similar

@jordanbisato
Copy link
Contributor

Isn't necessary to check if the TextField is empty before trigger the emptyField event?

@m1ga
Copy link
Contributor Author

m1ga commented Feb 1, 2024

as far as I can tell from testing it will only fire when the field is empty, so no text is in there and you press a key (See video above). You have to check the keyCode in Ti to see if it is the back key. I can add a check for the length but currently it looks like it is not necessary unless you have an example where it breaks

@m1ga m1ga added the feature label May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants