titanium-sdk icon indicating copy to clipboard operation
titanium-sdk copied to clipboard

feat(android): new event for empty TextFields

Open m1ga opened this issue 5 months ago • 2 comments

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();

https://github.com/tidev/titanium-sdk/assets/4334997/f10a081e-8810-4744-a685-d1d4f67d9d9e

TODO:

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

m1ga avatar Jan 26 '24 22:01 m1ga

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

jordanbisato avatar Feb 01 '24 13:02 jordanbisato

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 avatar Feb 01 '24 14:02 m1ga