titanium-sdk
titanium-sdk copied to clipboard
feat(android): new event for empty TextFields
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
Isn't necessary to check if the TextField is empty before trigger the emptyField event?
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